4

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?

LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45
  • In Swift it's highly recommended to use lightweight `JSONSerialization`, `PropertyListSerialization` or the `Codable` protocol rather than *objective-c-ish* `NSKeyed(Un)archiver` – vadian Dec 22 '18 at 09:52
  • I am familiar with Codable and I use it for "inAppCreatedObjects" but here I have to migrate data from an earlier IOS-Version within my app. – LukeSideWalker Dec 22 '18 at 15:48

1 Answers1

6

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

if let fileNames = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(dataObject) as? Array<String> {
    // ... 
}        
LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45