Questions tagged [nscoding]

NSCoding is a protocol from Apple Foundation framework. The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded.

The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces).

These two methods in the NSCoding protocol are:

  • encodeWithCoder: Encodes the receiver using a given archiver. (required)
    -(void)encodeWithCoder:(NSCoder *)encoder

  • initWithCoder: Returns an object initialized from data in a given unarchiver. (required)
    - (id)initWithCoder:(NSCoder *)decoder

And in Swift :

  • init(coder decoder: NSCoder!)

  • func encodeWithCoder(_ encoder: NSCoder!)

604 questions
0
votes
1 answer

Should I use Core Data or NSCoding to preserve a table view controller's data?

This is a pretty basic question, but I have searched all over for an answer that caters to my situation and found little. I'm using ECSlidingviewController to make a left drawer/menu control like Facebook, Pulse, and many others. (Actually quite…
user
  • 3,388
  • 7
  • 33
  • 67
0
votes
2 answers

How to save non property values in iOS using NSUserDefaults?

I am saving the AccessToken that I got from one Social Networking website.when I save this then I come to know that We can't directly save the non property values in iOS SDK. Then from tutorial I came to know that I should implement the NSCoding…
Imran Naseem
  • 17
  • 1
  • 9
0
votes
1 answer

Core Data app crashes on saving

I got the following error [context save:&error]. How should I fix? unrecognized selector sent to class * -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on it. * Terminating app due to…
yogwiz
  • 35
  • 6
0
votes
0 answers

Does decodeObjectForKey: result need to be copied for standard objects

If I am decoding standard objects like strings, arrays, and numbers, do I need to copy the result? It seems to me that decodeObjectForKey will always return a unique object in these cases: _foo = [coder decodeObjectForKey:@"foo"]; but I want to be…
Skotch
  • 3,072
  • 2
  • 23
  • 43
0
votes
0 answers

Include additional object when archiving with NSKeyedArchiver

I'm trying to archive a tree of objects using NSKeyedArchiver. All nodes in the tree support NSCoding, but I don't have access to the source code, so I can't change anything. However, I'd like to include an additional NSString with some of the nodes…
DrummerB
  • 39,814
  • 12
  • 105
  • 142
0
votes
1 answer

NSCoding and ARC

I'd like to archive my custom objects. ClassA holds a dictionary whose values are instances of ClassB. Everything looks good ClassA's initWithCoder, and _dictionary is declared strong, but after init returns and I call callMeAfterInit, the…
danh
  • 62,181
  • 10
  • 95
  • 136
0
votes
0 answers

Can you nest data encoding?

I am working on a turn-based Game Center game. I am trying to encode a custom class for which I have already written encodeWithEncoder and initWithEncoder. Those seem to work fine, except for two arrays of other little custom objects that don't…
Logan Shire
  • 5,013
  • 4
  • 29
  • 37
0
votes
0 answers

iOS 5: NSDictionary encodeWithCoder inserts nil into array

I am seeing a problem that seems to be unique to iOS 5, where trying to encode a dictionary results in a crash because an array is populated with a nil object in the process. This is confusing to me because I would think in order for the following…
Bryan Irace
  • 1,855
  • 2
  • 20
  • 38
0
votes
1 answer

Archiving NSArray that contains dictionaries

I am trying to save an NSMutableArray in CoreData. The Array contains objects NSDictionary NSDictionary has following Structure valueDict = { FloorId = F0001; endCoordinates = "NSPoint: {541, 413}"; linePath = "
ila
  • 920
  • 12
  • 35
0
votes
2 answers

Will longer keys make an NSKeyedArchiver file significantly longer

When I fill in the encodeWithCoder: for objective c classes for an iPhone app will it make make the archive file larger if I use long keys as opposed to short keys for all of my variables? For example if I use really long keys like this: [coder…
Jamvert
  • 76
  • 5
0
votes
1 answer

Saving data for use at runtime

I've got an iOS app I am trying to build that presents the user data from a .xlsx (MS Excel file) I have. The file has nearly 11,000 rows, with 20 columns per row. I have built a parser to transform each row into an subclass of NSObject, with each…
Joe Million
  • 147
  • 9
0
votes
0 answers

Removing a property from a class which implements results in 'class not key value coding-compliant'

I have a class which implements ˚ protocol and has the property netAbsAmount. I decided to remove it but now I am getting the following error: [ valueForUndefinedKey:]: this class is not key value coding-compliant for the key…
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
0
votes
0 answers

A good way to serialize changes in object graphs using NSCoding?

I have a graph of objects that support NSCoding. And I have a separate class that takes care of the serialization itself, ie. it detects changes in the object graph and uses NSKeyedArchiver to save it into a file. I’m fairly happy with the design,…
zoul
  • 102,279
  • 44
  • 260
  • 354
0
votes
1 answer

EXC_BAD_ACCESS when trying to deserialize a subclass object from AFHTTPClient

I have a subclass of AFHTTPClient with NSCoding protocol methods implemented: - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (!self) return nil; self.isLoggedIn = [aDecoder…
Kex
  • 776
  • 10
  • 22
0
votes
2 answers

Objective c - trouble with Archiving encode and decode

I am learning objective-c at the moment and up to the archiving and got stuck with encode and decode. here is my code. #import @interface Foo : NSObject @property (copy, nonatomic) NSString *strVal; …
Bill
  • 17,872
  • 19
  • 83
  • 131