Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mitchellporter/1b8c73c131399b4e4b6d2b9ff890b372 to your computer and use it in GitHub Desktop.

Select an option

Save mitchellporter/1b8c73c131399b4e4b6d2b9ff890b372 to your computer and use it in GitHub Desktop.
//: Mocks Playground
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)
}
extension UIApplication: PushNotificationRegistrar { }
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment