How to replace NSKeyedUnarchiver.unarchiveTopLevelObjectWithData with unarchivedObject when data is an array of Strings?

206 views Asked by At

My project recently shows this error in Xcode:

'unarchiveTopLevelObjectWithData' was deprecated in macOS 10.14: Use unarchivedObject(ofClass:from:) instead

I found this article which speaks to my exact problem:

How to replace NSKeyedUnarchiver.unarchiveTopLevelObjectWithData with unarchivedObject when data is a Dictionary

Except that my data is an array of strings, not a dictionary. So, because I can't leave a comment on that post, I'm asking this as a new question.

How can I get the below solution to apply to [String]?

let dictionary = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSDictionary.self, NSArray.self], from: data) as? NSDictionary
1

There are 1 answers

0
atoss On

The correct answer was:

let array = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, NSString.self], from: data) as? [String]