Paco1 Paco1 - 11 months ago 318
iOS Question

How to decode string using NSSecureCoding in Swift 3?

I am currently trying the iOS 10 Beta and decided to convert my Swift code to Swift 3. Until now, I was able to securely decode a String using

coder.decodeObjectOfClass(NSString.self, forKey: CoderKeys.code) as! String

After the conversion to Swift 3, Xcode is giving me the following error:

'decodeObjectOfClass(_:forKey:)' is unavailable in Swift: use generic 'decodeObjectClass(_:forKey:)'

As I mentioned, I'm using NSSecureCoding, so unfortunately
decodeObject(forKey: String)
won't do. Is this a beta bug? What am I missing?


It seems decodeObjectOfClass:forKey: is imported as generic decodeObject(of:forKey:) in Swift 3.

Try this:

coder.decodeObject(of: NSString.self, forKey: CoderKeys.code) as String?