Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 268
Paco1 Avatar asked Aug 03 '16 10:08

Paco1


1 Answers

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?
like image 137
OOPer Avatar answered Sep 29 '22 00:09

OOPer