Questions tagged [nskeyedunarchiver]

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyedArchiver class.

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyedArchiver class.

A keyed archive is encoded as a hierarchy of objects. Each object in the hierarchy serves as a namespace into which other objects are encoded. The objects available for decoding are restricted to those that were encoded within the immediate scope of a particular object. Objects encoded elsewhere in the hierarchy, whether higher than, lower than, or parallel to this particular object, are not accessible. In this way, the keys used by a particular object to encode its instance variables need to be unique only within the scope of that object.

Click Here for class reference.

203 questions
6
votes
1 answer

NSKeyedUnarchiver fails to decode a custom object in swift

I'm trying a basic implementation of the NSCoding protocol in swift, but it seems I can't success to unarchive an object after it has been correctly archived. Here's my attempt import Cocoa class User: NSObject, NSCoding { var name: String …
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
6
votes
0 answers

NSKeyedUnarchiver initForReadingWithData: incomprehensible archive crash

I have the following problem while unarchiving a file, which contains an xml string. It crashes at the following line: NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; 'data' (27580 bytes) comes…
Loxone Thomas
  • 133
  • 2
  • 6
5
votes
0 answers

App Auth crash when unarchiving AuthState

I'm implementing the App Auth library in my iOS app, and trying to clean up a couple warnings when archiving the Auth State. 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error:…
Dennis Calla
  • 839
  • 9
  • 10
5
votes
3 answers

NSCoder crash on decodeBool forKey (Xcode 8, Swift 3)

I have this simple class import UIKit class SimpleModel: NSObject, NSCoding { var name : String! var done : Bool! init(name:String) { self.name = name self.done = false } internal required init?(coder…
Enlil
  • 1,027
  • 14
  • 28
4
votes
2 answers

How to deal with deprecated function 'unarchiveObject(with:)'?

Try to implement KeychainWrapper from here: https://github.com/jrendel/SwiftKeychainWrapper It is functioning well but in one piece of code I get mistake: "'unarchiveObject(with:)' was deprecated in iOS 12.0: Use…
Roman
  • 759
  • 2
  • 9
  • 23
4
votes
3 answers

initForReadingWithData is deprecated - initForReadingFromData returns nil

I have the following warning (Xcode 10.1 - iOS 12.1) 'initForReadingWithData:' is deprecated: first deprecated in iOS 12.0 - Use -initForReadingFromData:error: instead* When I'm change the method to initForReadingFromData, the NSKeyedUnarchiver…
Frank Möller
  • 301
  • 2
  • 7
4
votes
1 answer

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…
LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45
4
votes
1 answer

NSKeyedUnarchiver.unarchivedObject returning nil for dictionary

I am trying to update my code to iOS12. Below is my code: class CurrentGameState: NSObject, NSSecureCoding { static var supportsSecureCoding: Bool = true var currentTest1 = Int() var currentUnitPositionColumn = [String: Int]() static var…
Delph2
  • 119
  • 1
  • 9
4
votes
2 answers

NSKeyedUnarchiver.unarchiveTopLevelObjectWithData is obsoleted in Swift 4

I tried to implement a fork of AwesomeCache that implements unarchiveTopLevelObjectWithData in Swift 4: if let data = NSData(contentsOfFile: path) { do { possibleObject = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
4
votes
1 answer

Why does NSKeyedUnarchiver exist when NSKeyedArchiver inherits from NSCoder?

To give some context, I'm new to iOS/Objective-C with a web dev (Ruby/JS/C#) background. I understand how the classes work, but I don't understand why the original implementors wrote these two classes (NSKeyedArchiver and NSKeyedUnarchiver) instead…
4
votes
1 answer

Decode and then encode unknown class with NSKeyedArchiver?

I've got a project file from OS X application that is a plist generated with NSKeyedArchiver. I need to programmatically change one string in it. Basically, it contains NSDictionary object with Foundation classes. But there is one custom class…
Vavius
  • 218
  • 2
  • 7
3
votes
0 answers

[MyClass initWithCoder:]: unrecognized selector sent to instance - On iOS16

I am using the [NSKeyedUnarchiver unarchiveObjectWithData:result] methode for unarchiving NSData in my objective c bases app. NSMutableArray *array = (NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:result]; This is working pretty fine…
3
votes
1 answer

NSKeyedUnarchiver data in wrong format

I'm using ARKit and GameKitMatches so I can't use Codable (afaik) because MCPeerID as well as ARWorldMap aren't codable, to get that out of the way first. So I'm using NSCoding and NSSecureCoding but for some reason I always catch the error: The…
thisIsTheFoxe
  • 1,584
  • 1
  • 9
  • 30
3
votes
1 answer

problem with NSKeyedUnarchiver unarchivedObjectOfClass: fromData:error;

NSMutableArray * array; array = [NSKeyedUnarchiver unarchiveObjectWithFile: mypath]; it is OK. NSData * data = [NSData dataWithContentsOfFile: mypath]; array = [NSKeyedUnarchiver unarchiveObjectWithData: data]; it is OK. The method I can't use…
Gianni
  • 51
  • 3
3
votes
2 answers

Save/Get UIColor from UserDefaults

I need some help to load and read UIColor from UserDefaults. I found a nice extension to do that: extension UserDefaults { func colorForKey(key: String) -> UIColor? { var color: UIColor? if let colorData = data(forKey: key) { color =…
Sqweelow
  • 187
  • 2
  • 13
1
2
3
13 14