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
1 answer

Watchkit sharing data with iPhone app, NSInvalidUnarchiveOperationException

From my iPhone app I'm sending data to my Watch app through: func application(application: UIApplication!, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]!, reply: (([NSObject : AnyObject]!) -> Void)!) { if let data =…
Bagbyte
  • 845
  • 2
  • 18
  • 34
2
votes
3 answers

iOS: count of objects (0) differs from count of keys

I have faced an issue which I have no idea what went wrong. I have a method for saving info into NSUserDefaults and then another method for retrieving it. But when I retrieve it the error message came up: *** Terminating app due to uncaught…
2
votes
3 answers

Where to store local variables? NSKeyedArchiver or NSUserDefaults?

bit of a noob here but what is the best way to save simple variables/arrays for an app? For example I have an app that has a friendList array and I want that to load each time the app starts? Would it be NSKeyedArchiver? NSUserDefualts? Or some…
Kex
  • 8,023
  • 9
  • 56
  • 129
2
votes
1 answer

NSKeyedArchiver duplication of encoding keys and iOS8 issues

I have an obj-c app with autolayout (iPhone 4s through 6 plus compatible) that runs fine in iOS7 (devices and simulator), when I run it on iOS 8 and above it still runs fine but I get the following errors in the console. *** NSKeyedArchiver warning:…
DavideC
  • 107
  • 10
2
votes
0 answers

Correctly archiving cross referencing Objective-C dictionaries

I have a system which I am trying to archive. The main data which I need to store is in two different trees. I will simplify it for examle Class A { B* Data } Class B { NSString* ParentKeyToATree } I am trying to archive this data where there…
David
  • 1,648
  • 1
  • 16
  • 31
2
votes
3 answers

When saving something to disk with NSKeyedArchiver, where is that stored on the iPhone?

Example: If I used this, where does the iPhone store the file? if (![NSKeyedArchiver archiveRootObject:your_object toFile:@"filename.plist"]) // save failed. On my mac the filename.plist goes to Macintosh HD directly. No folder. Also, the…
dontWatchMyProfile
  • 45,440
  • 50
  • 177
  • 260
2
votes
0 answers

Append data to file using NSKeyedArchiver

At some point in my program, I've saved 10 objects to a file at Documents directory, encoding each of them using NSKeyedArchiver. Now I want to add more objects to my file, but keeping the old ones. Is there a way to do that??? Here is some code: -…
2
votes
2 answers

Are objects modified when Archived/Unarchived?

So here is my problem. I am trying to archive an array of objects and when I unarchive them although the count is the same and the objects inside the root object are the same it does not find the specified object in the unarchived…
Scott
  • 1,154
  • 1
  • 12
  • 25
2
votes
1 answer

NSData vs. Archiving

I guess I just don't know what the difference is because I don't understand the "black box" but what is the difference between using either one of these methods? When should I be using NSData writeToFile: atomically: and when should I be…
Scott
  • 1,154
  • 1
  • 12
  • 25
2
votes
1 answer

[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0xffffffff, 0xffffffd8, 0xffffffff, 0xffffffe0, 0x0, 0x10, 0x4a, 0x46)

In my app i Archive myObject to NSData and then Unarchive NSData to get myObject. Crash trace 0 CoreFoundation 0x2fe9ef46 __exceptionPreprocess + 126 1 libobjc.A.dylib 0x3a1b36aa objc_exception_throw + 34 2 …
2
votes
1 answer

ios keyed archive Sprite Kit decode error: SKTexture: Error loading image resource: "Missing Resource.png"

When I archive SKLabelNodes and SKShapeNodes (I have not tried SKSpriteNotes) no problem, but when I extract the sprites from the archive i get SKTexture: Error loading image resource: "Missing Resource.png". Here is some example code that…
Howard Lovatt
  • 968
  • 1
  • 8
  • 15
2
votes
1 answer

storing MKRoute in Core Data

I am currently trying to store an MKRoute object in core data. All I really need from it is the MKPolyLine so if I can store that that's fine too. I've tried using NSKeyedArchiver but that just simply throws an exception and crashes my program. …
jsookiki
  • 522
  • 1
  • 6
  • 23
2
votes
1 answer

Will using an NSKeyedArchiver/NSCoder persist even after an application update?

I have NSKeyedArchiver and NSCoder data being persisted (as .txt files) and working great. When I deploy new builds to the iphone, the text files are still present - in other words, they are not being written over. However, I want to make sure that…
mr-sk
  • 13,174
  • 11
  • 66
  • 101
2
votes
1 answer

The initWithCoder: function is not called from unarchiveObjectWithData:

I'm trying to unarchive an array of objects of a particular type, but the initWithCoder: function does not get executed within the object's class. Instead, I'm given the error: *** Terminating app due to uncaught exception…
Taz
  • 1,203
  • 1
  • 11
  • 21
2
votes
2 answers

self referencing NSMutableDictionary

Say I have this: NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[@1] = @2; dict[@3] = dict; I archive dict by calling: NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict]; then I unarchive later: NSMutableDictionary…