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
10
votes
3 answers

NSKeyedArchiver fails with CLLocationCoordinate2D structs. Why?

I don't understand why I can archive CGPoint structs but not CLLocationCoordinate2D structs. What's the difference to the archiver? Platform is iOS. I'm running in the simulator and haven't tried on the device. // why does this…
TomSwift
  • 39,369
  • 12
  • 121
  • 149
9
votes
3 answers

NSData from NSKeyedArchiver to NSString

I'm trying to convert NSData generated from NSKeyedArchiver to an NSString so that I can pass it around and eventually convert it back to NSData. I have to pass this as a string (I'm using three20 URL passing). I've gone through various encodings,…
kodai
  • 3,080
  • 5
  • 32
  • 34
9
votes
1 answer

What format does NSKeyedArchiver save?

When I use NSKeyedArchiver is the data that is written a *.plist, I have seen some examples where people have the output file down as *.txt or even without an extension at all? -(void)saveCore { NSMutableData *data = [[NSMutableData alloc]…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
9
votes
1 answer

Differences with archiveRootObject:toFile: and writeToFile:

Recently, I'm learning about NSKeyedArchiver and NSKeyedUnarchiver. I found that there are three ways to archive an array and I'm trying to figure out the differences. 1.Using archiveRootObject:toFile: [NSKeyedArchiver…
kukushi
  • 647
  • 9
  • 22
8
votes
2 answers

NSKeyedUnarchiver - how to prevent a crash

I guess this is very obvious, but I have a question about loading data. If have a file called library.dat which stores all kind of information about objects in the app. It's set up all nicely (in terms of the initWithCoder and encodeWithCoder…
n.evermind
  • 11,944
  • 19
  • 78
  • 122
8
votes
3 answers

NSKeyedArchiver does not archive my Codable class

Here is my Codable class: class SensorOutput: Codable { var timeStamp: Date? var gyroX: Double? var gyroY: Double? var gyroZ: Double? var accX: Double? var accY: Double? var accZ: Double? var magX: Double? var…
8
votes
1 answer

NSCoding with as NSString inside a object

My issue is then I retrieve my NSArray of Store objects, all my NSString properties are causing BadAccess errors. The int and double properties work fine! store.h @interface Store : NSObject { NSString *Name; NSString *Address; …
8
votes
1 answer

Copying UIView using NSKeyedArchiver throws NSInvalidUnarchiveOperationException

Using this to copy UIView UIView copyOfView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:originalView]] This throws the following error: NSInvalidUnarchiveOperationException [NSKeyedUnarchiver…
Yadvendar
  • 955
  • 9
  • 14
7
votes
1 answer

How to encode and decode a custom class with NSKeyedArchiver

I have a custom class that I wish to save and load. The class contains an NSDate, an NSString, and an NSNumber. I have implemented the NSCoding protocol in the .h file. Here is the code I have so far. theDate is an NSDate. theName is the NSString.…
7
votes
4 answers

Unarchiving encoded data returning nil and incorrect format

I have added category methods to NSUserDefaults to store and retrieve encoded objects (in this case, an NSArray). I am having a problem retrieving the encoded data. Here is my code: - (void)encodeObject:(id)object forKey:(NSString *)key { …
mashers
  • 1,009
  • 7
  • 22
7
votes
3 answers

Serialization vs. Archiving?

The iOS docs differentiate between "serializing" and "archiving." Is this a general distinction (i.e., holds in other languages) or is it specific to Objective-C? Also, what is the difference between these two?
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
7
votes
1 answer

NSKeyedUnarchiver unarchiveObjectWithData returning nil

I have a class which serializes and deserializes with NSCoder/NSKeyedArchiver and NSKeyedUnarchiver. I have unit tests that are designed to check for my handling of various errors inside my serialization format (which is not a simple archive but…
Puppy
  • 144,682
  • 38
  • 256
  • 465
7
votes
2 answers

NSKeyedArchiver thread safe?

Do I need to worry about using archiveRootObject and unarchiveObjectWithFile in background threads? dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSKeyedArchiver archiveRootObject:myArray toFile:file]; });
Toydor
  • 2,277
  • 4
  • 30
  • 48
7
votes
2 answers

Loading a Singleton's state from NSKeyedArchiver

I have a class that I've made into a singleton and am able to save it's state using an NSKeyedArchiver, but I can't wrap my head around pulling it's state back out. In the function that does the loading I have Venue *venue = [Venue…
rob5408
  • 2,972
  • 2
  • 40
  • 53
6
votes
4 answers

Need to archive CLLocation data

I have an array of CLLocation data that I would like to archive. Should the NSUserDefaults system be used? Otherwise, how best to archive the CLLocation data?
devonsmith
  • 123
  • 2
  • 11
1
2
3
37 38