Questions tagged [nskeyedarchiver]

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.

A keyed archive differs from a non-keyed archive in that all the objects and values encoded into the archive are given names, or keys. When decoding a non-keyed archive, values have to be decoded in the same order in which they were encoded. When decoding a keyed archive, because values are requested by name, values can be decoded out of sequence or not at all. Keyed archives, therefore, provide better support for forward and backward compatibility.

Click Here for class reference

570 questions
4
votes
4 answers

Data protection on mobile devices

I'm storing some healthcare data on a mobile phone and I'd like to know what the best system of encryption is, to keep the data secure. It's basically a bunch of model objects, that I'm serializing and storing using NSKeyedArchiver / the equivalent…
Tejaswi Yerukalapudi
  • 8,987
  • 12
  • 60
  • 101
4
votes
2 answers

How to archive an NSArray of custom objects to file in Objective-C

Can you show me the syntax or any sample programs to archive an NSArray of custom objects in Objective-C?
suse
  • 10,503
  • 23
  • 79
  • 113
4
votes
1 answer

Will NSKeyedArchiver serialize the whole object hierarchy regardless of object type?

If I pass a super class object into -archivedDataWithRootObject:, but that object contains a subclass of the said super class; will that whole object graph be serialized to include the instance variables of the subclass or only the instance…
Michael
  • 6,561
  • 5
  • 38
  • 55
4
votes
1 answer

How to migrate an object which has been persisted with NSKeyedArchiver?

I'm using a version of Archiver and have run into an issue. In a previous version of my project a class, Challenge was serialized to disk //v1.0 @interface Challenge : NSObject { ... @property (nonatomic,strong) NSString *challengeId; …
Damo
  • 12,840
  • 3
  • 51
  • 62
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
2 answers

Using NSKeyedArchiver to generate XML from NSManagedObjects held in an NSDictionary

I have an NSDictionary, which contains a bunch of NSManagedObjects. I can then use NSKeyedArchiver to write this to an NSData object. These are generated using this method. Which works fine and allows me to save a section of schema to disc and then…
Will Johnston
  • 864
  • 4
  • 18
3
votes
1 answer

How to convert NSData to NSArray (or NSObject)

I did test this code, but it cause SIGABRT error. NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data] NSData is plist data with xml format. This code works fine. [urlData writeToFile:[self docPath] atomically:YES]; array =…
ChangUZ
  • 5,380
  • 10
  • 46
  • 64
3
votes
2 answers

Is it possible to pack a C struct into a NSKeyedArchiver in Cocoa?

I'm programming an iOS application which needs to communicate with a python app in a very effecient way thru UDP sockets. In the middle I have a bonjour service which serves as a bridge for my iOS app and host python app to communicate. I'm…
Nuno Santos
  • 1,476
  • 3
  • 17
  • 34
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
2 answers

"The data couldn’t be written because it isn’t in the correct format" occurs while archiving a custom class with NSKeyedArchiver

I was trying a new API in iOS12: [NSKeyedArchiver archivedDataWithRootObject:<#(nonnull id)#> requiringSecureCoding:<#(BOOL)#> error:<#(NSError * _Nullable __autoreleasing * _Nullable)#>] What I was trying to do is very simple, archive a custom…
Davis Hoo
  • 31
  • 1
  • 3
3
votes
0 answers

when to set NSKeyedArchiver(requiringSecureCoding: false) to true

I am updating some of my code which has been deprecated in IOS12. Below is the old code: let gameData : NSMutableData = NSMutableData() let archiver = NSKeyedArchiver(forWritingWith: gameData) …
Delph2
  • 119
  • 1
  • 9
3
votes
1 answer

Swift iOS ARKit Load ARWorldMap Data from File NSKeyedUnarchiver NSKeyedArchiver

I'm trying to save then load an ARKit ARWorldMap to a local file. I seem to have the saving working fine: func saveWorldMap() { ARView?.session.getCurrentWorldMap { [unowned self] worldMap, error in guard let map = worldMap else {…
Geoff H
  • 3,107
  • 1
  • 28
  • 53
3
votes
3 answers

iOS Document folder is not a directory and/or is missing

Trying to archive an array of Codable elements. do { let data = try PropertyListEncoder().encode(elements) let success = NSKeyedArchiver.archiveRootObject(data, toFile:self.archiveURL.path) print(success ? "Successful save" : "Save…
raistlin
  • 4,298
  • 5
  • 32
  • 46
3
votes
1 answer

Catching exceptions when unarchiving using NSKeyedUnarchiver

We've got a Swift class which inherits from NSObject and implements NSCoding. We need to change the name of the class in code and in the archives on disk. Fortunately, we don't need to retain the data. Wiping the cached files and returning default…
Dale Myers
  • 2,703
  • 3
  • 26
  • 48