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

Saving nested objects and NSArrays in Objective C using NSCoding

I'm attempting to save an object that has an NSMutableArray of nested objects. I want to use the NSCoding Protocol to save the file under the documents directory. Do I need to encode every object (including the nested ones) or just the super class…
Stuartsoft
  • 1,000
  • 1
  • 8
  • 20
0
votes
2 answers

Saving multiple map annotations - crashes

I have been searching top and bottom for info on how to do this. I landed on a great tutorial! So I am still quite newbie to this. Basically I have been trying to store Map View annotations to an array. The annotations are a separate class which…
MCKapur
  • 9,127
  • 9
  • 58
  • 101
0
votes
1 answer

NSDictionary or NSKeyedArchiver

In the Model portion, I have some data types whose properties are all property list data types. Eventually, users will be sending each other these data items over the network by posting to and reading from a server. The question is, should I be…
William Entriken
  • 37,208
  • 23
  • 149
  • 195
0
votes
3 answers

NSCoding a ccColor3B field

I have a ccColor3B property in my class which I'd like to persist using NSCoding. How can I achieve this? NSCoder does not seem to have a method which allows it.
Rory Harvey
  • 2,579
  • 2
  • 22
  • 27
0
votes
1 answer

Searching Functions in Objective C

I have a strange task. I need to get an array that contains all the functions in an objective c object. I then need to be able to tell if each function is a class method or not. Then I need to get the names (preferably an NSString) of each parameter…
Ben Trapani
  • 271
  • 1
  • 4
  • 11
0
votes
1 answer

Trying to use NSCoder crashes the app on start-up

I have some details stored inside an NSDictionary. I'm using a Master-Detail view on iPad and after I added the initWithCoder method, my app crashes on start-up and I don't know how to make it work. The reason I want to use NSCoder is to store my…
Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36
0
votes
1 answer

Objective-c - initWithCoder and memory management?

I'm getting a leak in initWithCoder method. Does unarchiveObjectWithData:cacheData return me an autoreleased object? whose responsible to release the object return from unarchiveObjectWithData:cacheData? @implementation MyObject @synthesize…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
0
votes
1 answer

CCSprite + NSCoding

I have subclassed NSCoding and added my game specific stuff to it such as health etc. I have serialised the object I have subclassed however upon decoding and then adding the sprite to the screen via [self addChild:sprite], it fails to draw the…
godzilla
  • 3,005
  • 7
  • 44
  • 60
0
votes
1 answer

Save singleton object to disk - native Iphone app

I'm having some troubles trying to save a singleton object to the iPhone disk. The object is a collection of 2 arrays, which contain the faved posts and faced jobs. Basically --> Favorites = arrayOfFavedPosts + arrayOfFavedJobs Now I am trying to…
0
votes
1 answer

Programmatically loading an object model created using NSCoding

Version 1.0 of an application has a data model, which is saved/loaded using the NSKeyed(Un)Archiver classes, as all model classes adhere to the NSCoding protocol. Say the following hierarchy exists: -> Houses (NSMutableArray) -> -> House (Custom…
Craig Otis
  • 31,257
  • 32
  • 136
  • 234
0
votes
1 answer

Convert iOS app from NSCoding to Core Data

My app currently uses NSCoding to store persistent data, but I would like to make the switch to Core Data to take advantage of its integration with iCloud. The problem is that the app is currently live on the App Store, and I'm afraid that, once I…
roadkill
  • 315
  • 1
  • 2
  • 12
0
votes
1 answer

Injecting into NSData (Generated from NSCoding) from External Source?

We have an Application that we use NSCoding to archive our object data into NSData. We then take the NSData and send it to an XML parser and send it up to a Cloud server for storage. We have a Customer that wants to be able to alter, or Create…
scooter133
  • 1,297
  • 1
  • 15
  • 29
0
votes
1 answer

Cocoa - Where does NSCoding save?

what is the default saving location of NSCoding protocol? Also, is there any way to change such a default location to say, the folder where the .app file is located?
Kevin
  • 1,469
  • 2
  • 19
  • 28
0
votes
2 answers

how to implement applicationWillTerminate in appDelegate.m

I'm trying to save some data in a class named MyPos.h which uses the NSCoding methods: (void)encodeWithCoder:(NSCoder *)aCoder (id)initWithCoder:(NSCoder *)aDecoder These two methods have been implemented in the MyPos.m file. Now I want the…
gotfunk
  • 39
  • 6
-1
votes
2 answers

How to add new key and value to existing keyed archives using NSCoding

Trying to add a new key "password". Existing version of the app has these existing keys "name", "ip", "port", and has stored values. When the new key "password" is added, the app fails to read the existing data, and shows this error "Unable to…
Kevin W
  • 31
  • 4