Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSKeyedUnarchiver changes in iOS12 - How to unarchive an Array of Strings

There were some changes in Foundation from iOS 11.4 to iOS12. Unfortunately I couldn't find any helpful documentation on this topics.

Before iOS12 i had this code working perfectly to read an Array with Strings from a certain filePath:

if let myList : Array<String> = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? Array<String> {
   // ...
}

As I found out, there are some new methods in iOS12 that I should use and I tried this (in a do-catch-structure of course, and after getting the data object):

let myList : Array<String> = try NSKeyedUnarchiver.unarchivedObject(ofClass: Array<String>, from: data)

I also tried this without success:

let myList : Array<String> = try NSKeyedUnarchiver.unarchivedObject(ofClass: Array<String>.self, from: data)

Any recommendation?

like image 442
LukeSideWalker Avatar asked Oct 20 '25 08:10

LukeSideWalker


1 Answers

Finally I found out myself. It worked with this method:

if let fileNames = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(dataObject) as? Array<String> {
    // ... 
}        
like image 122
LukeSideWalker Avatar answered Oct 22 '25 00:10

LukeSideWalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!