Skip to content

Instantly share code, notes, and snippets.

@eliperkins
Last active October 23, 2019 05:03
Show Gist options
  • Select an option

  • Save eliperkins/8f4115151497dc1953ea to your computer and use it in GitHub Desktop.

Select an option

Save eliperkins/8f4115151497dc1953ea to your computer and use it in GitHub Desktop.

Revisions

  1. eliperkins revised this gist Oct 1, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions MocksPlayground.swift
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //: Playground - noun: a place where people can play
    //: Mocks Playground

    import UIKit

    @@ -24,6 +24,8 @@ protocol PushNotificationRegistrar {
    func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings)
    }

    extension UIApplication: PushNotificationRegistrar { }

    class FauxRegistrar: PushNotificationRegistrar {
    var registered = false
    func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings) {
    @@ -35,4 +37,4 @@ var registrar = FauxRegistrar()
    var controller = PushNotificationController(registrar: registrar)
    controller.user = User()

    registrar.registered // true
    registrar.registered
  2. eliperkins created this gist Oct 1, 2015.
    38 changes: 38 additions & 0 deletions MocksPlayground.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    //: Playground - noun: a place where people can play

    import UIKit

    struct User {
    }

    struct PushNotificationController {
    let registrar: PushNotificationRegistrar
    init(registrar: PushNotificationRegistrar) {
    self.registrar = registrar
    }

    var user: User? {
    didSet {
    if let _ = user {
    registrar.registerUserNotificationSettings(UIUserNotificationSettings())
    }
    }
    }
    }

    protocol PushNotificationRegistrar {
    func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings)
    }

    class FauxRegistrar: PushNotificationRegistrar {
    var registered = false
    func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings) {
    registered = true
    }
    }

    var registrar = FauxRegistrar()
    var controller = PushNotificationController(registrar: registrar)
    controller.user = User()

    registrar.registered // true