Latest | 1.0.0 |
---|---|
Homepage | https://github.com/lovellx/TypedNotification |
License | MIT |
Platforms | ios 8.0, requires ARC |
Frameworks | Foundation |
a convenient way to use Notifications,reduce hardcode
Installation
pod 'TypedNotification'
or just copy the file to your project
Example
- Define
extension Notification.Name {
static let test = Notification.Name.init("com.typedNotification.test")
}
struct TestNotificaiton: TypedNotification {
var name: Notification.Name { return .test }
var userInfo: [AnyHashable : Any]? {
return ["passedNum": num, "passedStr": str]
}
var num: Int
var str: String
init(_ notification: Notification) {
num = notification.userInfo!["passedNum"] as! Int
str = notification.userInfo!["passedStr"] as! String
}
init(_ num: Int, str: String) {
self.num = num
self.str = str
}
}
- Post
let testDescriptor = TestNotificaiton.init(1, str: "it is fine")
testDescriptor.post()
- Recieve
let token = TestNotificaiton.observer(for: .test) { (testObj) in
print("(testObj.num) (testObj.str)")
}
## License
TypedNotification is under MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "TypedNotification", "version": "1.0.0", "summary": "an awesome way to send and recieve a typed notification.", "homepage": "https://github.com/lovellx/TypedNotification", "license": { "type": "MIT", "file": "FILE_LICENSE" }, "authors": "lovellx", "platforms": { "ios": "8.0" }, "source": { "git": "https://github.com/lovellx/TypedNotification.git", "tag": "1.0.0" }, "source_files": "TypedNotification/TypedNotification/Core/*.swift", "frameworks": "Foundation", "requires_arc": true }
Fri, 03 Aug 2018 13:40:11 +0000