This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SavedImagesViewController.swift | |
// Kuoter | |
// | |
// Created by Leone Parise Vieira da Silva on 01/10/16. | |
// Copyright © 2016 Kuoter. All rights reserved. | |
// | |
import UIKit | |
import RxDataSources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol NotificationType { | |
var name: Notification.Name { get } | |
static var name: Notification.Name { get } | |
var userInfo: [AnyHashable : Any] { get } | |
init?(notification: Notification?) | |
} | |
struct Notifications { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol NotificationType { | |
/// Notification name | |
var name: Notification.Name { get } | |
/// Notification name | |
static var name: Notification.Name { get } | |
/// Notification parameters | |
var userInfo:[AnyHashable : Any] { get } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Notifications { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NotificationCenter { | |
func post(_ notification:NotificationType, object:Any? = nil) { | |
post(name: notification.name, object: object, userInfo: notification.userInfo) | |
} | |
func addObserver<T:NotificationType>(forType type: T.Type, object obj: Any? = nil, queue: OperationQueue? = nil, | |
using block: @escaping (T?) -> Swift.Void) -> NSObjectProtocol { | |
return addObserver(forName: type.name, object: obj, queue: queue) { | |
block( type.init(notification: $0) ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Notifications { | |
struct openUserProfile:NotificationType { | |
var userId:String | |
static var name: Notification.Name { | |
return Notification.Name(“LP_openUserProfile”) | |
} | |
var name:Notification.Name { | |
return openUserProfile.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NotificationCenter.default.post(Notifications.openUserProfile(userId:"someId")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let NC = NotificationCenter.default | |
let openUserProfileObserver = NC.addObserver(forType: Notifications.openUserProfile.self) { notification in | |
print(notification.userId) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol RemoteNotificationType: NotificationType { | |
var title:String? { get } | |
var alert:String? { get } | |
init?(userInfo: [AnyHashable : Any ]) | |
} |
OlderNewer