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

How to write Dictionary to a file?

I have a FileHelper class where I've implemented 3 methods whose job is to write a Dictionary contents to a file. Those methods are: func storeDictionary(_ dictionary: Dictionary, inFile fileName: String, atDirectory directory:…
nayem
  • 7,285
  • 1
  • 33
  • 51
3
votes
3 answers

Saving NSMutableArray to NSUserDefaults using NSKeyedArchiver

I'm having trouble retrieving a saved NSMutableArray containing a custom object. The app crashes and the console reports http://pastie.org/1226822. Here is my objects .h file http://pastie.org/1226823. Here is my objects .m file…
enbr
  • 1,203
  • 10
  • 16
3
votes
1 answer

Swift - Saving user data using NSKeyedArchiver, getting error on conversion to NSArray

So I have an array of custom objects. When I try to save the array to NSUserDefaults, I have to archive them. Here is what I am doing to archive the array of my custom objects : override func tableView(tableView: UITableView, numberOfRowsInSection…
Code Wiget
  • 1,540
  • 1
  • 23
  • 35
3
votes
1 answer

Encoding and decoding custom objects

I'm having trouble encoding and saving a list of custom objects containing a MKMapItem to NSUserDefaults. Firstly, I get the selected MKMapItem from an array of MKMapItems used for a tableView and store that in my sharedManager instance. (All the…
Erik
  • 2,500
  • 6
  • 28
  • 49
3
votes
1 answer

Unarchiving SKSpriteNode corrupts the SKTexture of the sprite in iOS 7.1, fine otherwise

I am using NSKeyedArchiver to archive an NSMutableDictionary that contains an NSMutableArray of subclassed SKSpriteNodes. Its a card game where i'm saving some game stats and then an array of sprites associated with the game. Archival is working…
Matt Fiocca
  • 1,533
  • 13
  • 21
3
votes
1 answer

nskeyedarchiver doesn't work on ios8 but works on ios7 and simulator

So I'm using NSKeyedArchiver for a wishlist and it works perfectly on iOS 7 and on simulator, but not on devices with iOS 8. Here the code I'm using: wishlist.m - (void)viewDidLoad { NSString *voirexpo = @"viensdeexpo"; [[NSUserDefaults…
Aly Srour
  • 33
  • 3
3
votes
1 answer

How to persist and load an object which conforms to NSCoding protocol?

I have made an class which conforms to the NSCoding protocol and does all the encode and decode stuff. For my app, I simply want to persist an object from that class to the device and the next time when the app launches, I want to load that object…
dontWatchMyProfile
  • 45,440
  • 50
  • 177
  • 260
3
votes
1 answer

NSKeyedArchiver file - losing data

Using Iphone SDK 3.1.2. I am saving some info to a file using NSKeyedArchiver object. I have 4 keys. I read data from the file for all 4 keys on applicationDidFinshLaunching and write back to the file (all 4 keys) on applicationDidTerminate. Also…
tech74
  • 1,355
  • 3
  • 21
  • 35
3
votes
2 answers

UserDefaults/KeyedArchiver Frustrations

I'm working on a homework app that uses custom Assignment objects for each assignment. I am trying to store an NSMutableArray (casted to an NSArray via initWithArray:) in standardUserDefaults but I'm having trouble with saving and reloading the…
azban
  • 421
  • 1
  • 4
  • 10
3
votes
1 answer

iOS archiving object with NSCoding failed

So I want to archive my object into by app sandbox documents directory. I copied most of the code from Big Nerd Ranch's iOS programming, so I don't see what could possibly go wrong. Is there anyway I could diagnose which part of the process is not…
harinsa
  • 3,176
  • 5
  • 33
  • 53
3
votes
2 answers

NSKeyedArchiver archiveRootObject keeps returning NO

I've spent the past few hours trying to figure this out, but I've ran out of ideas. All I'm trying to do is archive an object, but the method archiveRootObject keeps on returning NO Here's my code: NSArray *paths =…
Khon Lieu
  • 4,295
  • 7
  • 37
  • 39
3
votes
1 answer

Use Xcode Instruments to look at non-zombie object history at pointer

I am currently debugging a "message sent to deallocated object" error using Instruments. I am able to access the history of the object at fault through a "Zombie Messaged" dialog box. I want to find a similar object during runtime which is…
3
votes
1 answer

Any way to parse NSKeyedArchiver on Android / Java?

I've got some files saved from an iOS app using a NSKeyedArchiver but now I need to be able to read and write to this from an Android utility? Is there any Java library out there that deals with binary plists created using 'NSKeyedArchiver'?
strange
  • 9,654
  • 6
  • 33
  • 47
3
votes
1 answer

NSKeyedArchiver archiveRootObject and NSFileProtectionComplete/NSFileProtectionCompleteUnlessOpen

Is it actually possible to call NSKeyedArchiver archiveRootObject and work with data protection API setting the file attribute to NSFileProtectionComplete or NSFileProtectionCompleteUnlessOpen ?
jdrm
  • 621
  • 2
  • 8
  • 21
3
votes
1 answer

What’s the difference beetween NSCoder’s encodeObject: and encodeObject:forkey:?

In NSCoder, you can call encodeObject: and encodeObject:forkey:. And this for many data types. What is the difference beetween those calls? How to use them? Why isn't there a encodeDataObject:forkey: or encodePropertyList:forKey:?
Oliver
  • 23,072
  • 33
  • 138
  • 230