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
2
votes
2 answers

encodeWithCoder is not called in derived class of the NSMutableDictionary

Basically I am using some open source code called OrderedDictionary that is derived from NSMutableDictionary. Then I want to save the ordered dictionary data to NSUserDefaults by adding encode and decode method to the OrderedDictionary class.…
trillions
  • 3,669
  • 10
  • 40
  • 59
1
vote
1 answer

Serialization array of custom objects iOS

I know there is a lot of resources about that here but yet, I can't find what's going wrong with my code: I have a class Level and two subclasses of Level: GameLevel and TransitionLevel. Each of this class implements the NSCoding protocol. Then,…
rmonjo
  • 2,675
  • 5
  • 30
  • 37
1
vote
0 answers

EXC_BAD_ACCESS when using awakeAfterUsingCoder with ARC

I recently changed a bit of code using Archiver to replace the object being decoded with another if the object was in a shared list. My app is using ARC. - (id)awakeAfterUsingCoder:(NSCoder*)decoder { Player* player = [[Team getCurrentTeam]…
1
vote
1 answer

Archiving UIImageView with NSCoding

I've never used NSCoding before and I'm very confused about how it should be implemented. My current iPad app has a UIImageView (called "background") which is a property of my main view controller. "background" has a UIImage "image" property…
beev
  • 1,197
  • 2
  • 16
  • 33
1
vote
1 answer

NSKeyedUnarchiver not behaving as expected

I have come across an odd behaviour in NSKeyedUnarchiver. I archive a data, for this example I just use a string: NSMutableData *myData = [ NSMutableData data ]; NSKeyedArchiver *archiver = [[ NSKeyedArchiver alloc ]…
reza23
  • 3,079
  • 2
  • 27
  • 42
1
vote
2 answers

Save multiple custom UIImageViews

I was recently examining the project "Demo Photo Board" found here. This is a simple demonstration of adding UIImageViews to the screen that have UIGestureRecognizers added to them...allowing the user to manipulate the various UIImageViews. I add…
1
vote
2 answers

How to append data to NSKeyedArchive?

I'm reading a file like so: NSData *data = [NSData dataWithContentsOfFile:myPath]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; NSData *imgData = [unarchiver decodeObjectForKey:@"myimage"]; if (imgData…
anna
  • 2,723
  • 4
  • 28
  • 37
1
vote
1 answer

About NSException from "NSKeyedUnarchiver unarchiveObjectWithFile :"

NSArray *t_annos; @try { NSLog(@" --- pointer before = %ld --- ", (long) t_annos); t_annos = [NSKeyedUnarchiver unarchiveObjectWithFile : d_path]; NSLog(@" --- pointer after = %ld --- ", (long) t_annos); } @catch (NSException *e)…
Stanley
  • 4,446
  • 7
  • 30
  • 48
1
vote
0 answers

Adding a subclass of NSManagedObject Item to the UIPasteboard - Cut, Copy, Paste

I'm trying to implement Cut, Copy, Paste in my Application. The Items that I would like to store on the UIPasteboard are a subclasses of NSManagedObject. I followed this answer and it was great up until I need to copy the relationships. I started…
scooter133
  • 1,297
  • 1
  • 15
  • 29
1
vote
1 answer

NSKeyedArchiver and description method : app crashes

i tried to test NSKeyedArchiver, but my code seems to be wrong. I then tried only with a NSLog, but the NSLog returns (null) if i alloc-init my var "model" in the init method (in the controller), and it makes the app crash if i put it in…
Paul
  • 6,108
  • 14
  • 72
  • 128
1
vote
1 answer

Storing OpaquePointer type in UserDefaults

I am working on Xcode 12 and Swift 5 environment to build an iOS application. I need to store an OpaquePointer type variable("self.loggers" in the code below) before the view disappears(or before the app closes) and retrieve it when the view…
1
vote
1 answer

NSSecureCoding: Writing UIView to disk

Is it possible to write a UIView to disk using NSSecureCoding. The below code results in an error. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:object requiringSecureCoding:YES error:&error]; Error: The data couldn’t be written…
user1752054
  • 372
  • 4
  • 17
1
vote
1 answer

Why is NSArray of NSNumber(s) failing to decode?

I have a custom class that conforms to NSSecureCoding. I'm trying to encode its data, write it to a file, and decode it. The class contains an int array which I convert to an NSArray filled with NSNumber elements before encoding. When I decode the…
1
vote
1 answer

memory leak when decoding a NSArray with NSKeyedUnarchiver decodeObjectForKey

I'm trying to fix a huge memory leak that is caused somewhere in a method, that gets a NSData object from a CoreData datastore and unarchives that NSData back into a NSArray. - (CustomObject *) getCustomObject { .... get myManagedObject from…
ovm
  • 2,452
  • 3
  • 28
  • 51
1
vote
2 answers

How do I archive two objects using NSKeyedArchiever?

Previously, I have an array in which I use NSKeyedArchiver to archieve. [NSKeyedArchiver archiveRootObject:array toFile:docPath]; Called on applicationWillTerminate and applicationDidEnterBackground. Upon starting up, in…
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89