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

Map a multi-level JSON object to NSManagedObject with Hyperolso Sync

I'm using the great Sync from HyperOslo to get a JSON object from an API: JSON object: {"user": {"name" : "damien", "email" : "myemail@gmail.com", "settings" : { "notification" : "true", "secretKey" : "dzadd7z5a7dzd5azd" } …
Damien Romito
  • 9,801
  • 13
  • 66
  • 84
1
vote
1 answer

Swift: Unable to save tuples having more number of records in NSUserDefaults

I am trying to store tuple in NSUserDefaults. My tuple is below. var primaryNumberAndName: [(name:String , number: String, numberType: String, imageProfile: UIImage, imageLogo: UIImage)] = [] Adding datas to tuples for (var i : Int = 0; i <…
McDonal_11
  • 3,935
  • 6
  • 24
  • 55
1
vote
1 answer

Xcode crashes with Unrecognized selector when trying to use NSKeyedArchiver.archiveRootObject

I have a custom Swift Class which writes data to the file system using NSKeyedArchiver. One of the functions in this class to do the job is: func writeDataToArchive (data: AnyObject) { let dirPath = "\(currentPath)/\(fileName)" //---- …
Lavvo
  • 1,024
  • 3
  • 16
  • 35
1
vote
3 answers

How to archive and unarchive an NSObject?

I am trying to archive an NSObject that I send through match data in a game center turn based game. Below is my code for archiving my object turnDataObject MyData = [[turnDataObject alloc] init]; data = [NSKeyedArchiver…
Sooc
  • 141
  • 7
1
vote
0 answers

Why does initWithCoder: return the wrong object class during object decoding?

I'm attempting to use NSKeyedArchiver / NSKeyedUnarchiver in a trivial test case and observing that when initWithCoder: is called, the object that is created reports that it has the wrong class. TestCoder.h #import…
AlleyGator
  • 1,266
  • 9
  • 13
1
vote
1 answer

Can I save an NSData object to a file as binary?

I'm trying to save data to a file in binary format so the file size is as small as possible. But it seems that NSPropertyListFormat.BinaryFormat_v1_0 does not actually create binary data but instead creates an XML-style format exactly the same as…
RobertL
  • 14,214
  • 11
  • 38
  • 44
1
vote
1 answer

How to save and retrieve class object from NSUserDefaults swift?

I'm trying to save my array to NSUserDefaults. But my Array exist with struct. struct MyData { var Text = String() var Number = Int() } var Data = [MyData]() I found this and I tried to do this; let Data2 =…
1
vote
0 answers

NSNumbers in archived array dissappear

Okay I've made an array of NSNumber objects that I've stored into an NSMutableArray. When the game loads it's unarchived and retained but all the NSNumber objects are gone. Here's my code: times = [[NSMutableArray alloc] initWithObjects:[[NSNumber…
1
vote
1 answer

what happens in iOS when nscoding writeToFile is saving and user closes the app?

what happens in iOS when nscoding writeToFile is saving and user closes the app? NSData *d = [NSKeyedArchiver archivedDataWithRootObject:self]; [d writeToFile:FILE_PATH atomically:YES]; For example suppose there is 100 MB of user data to…
user1709076
  • 2,538
  • 9
  • 38
  • 59
1
vote
1 answer

Save NSMutableArray of NSStrings to disk

I have a NSMutableaArray of NSString objects. So i'm using NSKeyedArchiever to save it to disk. So when i try to use - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:self.EventsList forKey:@"Events"]; } i got an error …
pavel_s
  • 465
  • 1
  • 7
  • 27
1
vote
1 answer

NSMutable dictionary, do I initialise every time it is used or save and load it to file?

I have a class that uses a NSMutableDictionary. This dictionary contains between 40-60 objects of a custom class "appStrings". Right now every time I used the class I just init the dictionary calling my initDictionary method and this adds all the…
Kex
  • 8,023
  • 9
  • 56
  • 129
1
vote
3 answers

Custom class archiving in Swift

I would like to archive and unarchive a custom object in swift, something like this: class Line : NSObject, NSCoding { var start : CGPoint init(start _start: CGPoint) { start = _start } required init(coder aDecoder:…
szuniverse
  • 1,076
  • 4
  • 17
  • 32
1
vote
1 answer

NSKeyedArchiver on NSArray has large size overhead

I'm using NSKeyedArchiver in Mac OS X program which generates data for iPhone application. I found out that by default, resulting archives are much bigger than I expected. Example: NSMutableArray * ar = [NSMutableArray arrayWithCapacity:10]; for…
BobK
  • 860
  • 6
  • 12
1
vote
1 answer

Archiving multiple items

I'm working on a document-based app without CoreData. I have a class Player, which is a subclass of NSObject. The class has some variables and I have also properly implemented - (id)initWithCoder:(NSCoder *)coderand - (void)encodeWithCoder:(NSCoder…
Yashman
  • 111
  • 1
  • 11
1
vote
1 answer

NSKeyedUnarchiver chokes when trying to unarchive more than one object

We've got a custom matrix class, and we're attempting to archive and unarchive an NSArray containing four of them. The first seems to get unarchived fine (we can see that initWithCoder is called once), but then the program simply hangs, using 100%…
ajduff574
  • 2,101
  • 1
  • 21
  • 20