TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jun 2016 |
SPMSupports SPM | ✗ |
Maintained by tarunon.
Convert your own struct/enum to AnyObject easily.
In swift, struct or enum cannot convert to AnyObject
NSNotificationCenter.defaultCenter().postNotificationName("foo", object: YourOwnStruct()) // Fail
Of course, you may wrap value using Box<T>.
class Box<T> {
let value: T
init(value: T) {
self.value = value
}
}
NSNotificationCenter.defaultCenter().postNotificationName("foo", object: Box(value: YourOwnStruct())) // OK
But Box<T> unwrap is too lazy.
let value = (notification.object as? Box<YourOwnStruct>)?.value
You can cast your struct/enum directory if implement AnyObjectConvertible at that type.
extension YourOwnStruct: AnyObjectConvertible {}
NSNotificationCenter.defaultCenter().postNotificationName("foo", object: YourOwnStruct()) // OK
let value = notification.object as? YourOwnStruct
Use Carthage.
github "tarunon/AnyObjectConvertible"
MIT