Created
February 1, 2016 12:13
-
-
Save jk/eb86682c2e6797388d12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 NSCoder { | |
// works but not optimal | |
func encodeProtocol<T: SequenceType>(objv: T, forKey key: String) { | |
let aCollection = objv.map { $0 as! AnyObject } | |
self.encodeObject(aCollection, forKey: key) | |
} | |
// want: func encodeObject<T: SqeuenceType where T.Element is AnyProtocol>(objv: T, forKey key: String) { ... } | |
func decodeObjectForKey<T>(key: String) -> [T] { | |
let unspecifiedCollection = self.decodeObjectForKey(key) as! [AnyObject] | |
return unspecifiedCollection.map { $0 as! T } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment