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

NSUserdefaults not working with NSKeyedArchiver

I have a NSMutableArray filled with objects of my Movie class wich i want to save but it doesn't work and i can not figure out why... Movie.h: @interface Movie : NSObject { NSString *name; int year; int length; NSString…
0
votes
0 answers

IOS Where To Persist Current User from Back-end

I am using an IOS app with a Rails Back-end. When the user opens the app, I want to query its profile from the server and set a current user method in order to call it somewhere else in the app without querying it again from the server. I would also…
stefano_cdn
  • 1,362
  • 2
  • 15
  • 29
0
votes
1 answer

Problems Saving NSMutableArray with custom objects

I have a class called CurrentUser, which holds a NSMutableArray called listOfFriends. This listOfFriends holds objects from the class Friends. Both CurrentUser and Friend classes have the NSCoding protocols handled. The Friend object has a property…
Fred Novack
  • 727
  • 9
  • 27
0
votes
1 answer

passMessageObject from ObjC to Swift (wormhole)

Trying to use "WormHole" in Swift (from link), the following translation from Objective C to Swift does not seem to work. Do you have any hint on how to do it ? My Swift-code (not working yet!!!) is: class ViewController: UIViewController { …
iKK
  • 6,394
  • 10
  • 58
  • 131
0
votes
2 answers

NSCoding gamedata not saved swift

At the moment, my data does not get retrieved in another new session and it uses the default values. Do I have to have an existing plist file for this to work? I tried using an existing file with no luck. I followed the guide here…
Wraithseeker
  • 1,884
  • 2
  • 19
  • 34
0
votes
1 answer

Archiving and unArchiving custom objects with NSCoder

I am trying to archive an array of photo() objects with some members in it. Given that NsCoding protocol has been implemented correctly, will the following code work to successfully archive (save) the data from the array and anarchive it again? var…
Bahram Ghebray
  • 107
  • 1
  • 11
0
votes
2 answers

Encoding excerpts from collection of objects that do not themselves conform to NSCoding

I would like to serialize excerpts from a collection of objects that do not themselves conform to NSCoding to a file. What's the best way to achieve this without transformation the collected objects an intermediary representation (one that would…
Drux
  • 11,992
  • 13
  • 66
  • 116
0
votes
1 answer

How can data be stored on an iPhone/iPad based on data volume?

I am to make a app which will connect to a remote DB server and fetch images and product descriptions as text. Each product will have 3-5 images. How is the best way to store the data I have got from the web server? Using NSUserDefault wont work,…
MB_iOSDeveloper
  • 4,178
  • 4
  • 24
  • 36
0
votes
1 answer

NSCoding Serialization of iPhone NavigationController stack

EDIT: I seem to have found something that's helped. I retained the ivar "stack" and now it seems to be working I have been serializing several custom NSObject classes without issue. Now I'd like to serialize my NavigationController stack. Each…
Daddy
  • 9,045
  • 7
  • 69
  • 98
0
votes
1 answer

Can I do this?? Trying to load an object from within itself

I have an object which conforms to the NSCoding protocol. The object contains a method to save itself to memory, like so: - (void)saveToFile { NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver…
Smikey
  • 8,106
  • 3
  • 46
  • 74
0
votes
1 answer

NSCoding save NSMutableArray on shutdown and load on startup

I am trying to save a NSMutableArray when the app shuts down, and then load it on startup to a tableview. Here's my code: - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:_savedText forKey:@"savedText"]; } -…
0
votes
1 answer

non-persistence of object written to documentsDirectory - is

-- a question about how to make an object that is saved to the documents directory persist on the drive and be recoverable after the iDevice is rebooted. Here's my problem. I make a data object with NSCoding and fill it with data. I write it to the…
user1976727
  • 71
  • 10
0
votes
3 answers

Using NSCoder and NSKeyedArchiver with runtime reflection to deep copy a custom class

I'd like to use - (id)initWithCoder:(NSCoder *)coder and - (void)encodeWithCoder:(NSCoder *)coder to encode a custom class for copying (using NSKeyedArchiver etc) My custom class contains a large number of iVars. Instead of listing all of these…
whatdoesitallmean
  • 1,586
  • 3
  • 18
  • 40
0
votes
0 answers

NSCoding Class with Transient Properties

I'm using NSKeyedArchiver / NSKeyedUnarchiver along with NSCoding compliant classes to persistently store data in an application. I'd ideally like to have a few properties within the class which aren't persistently stored (as there is no need to…
Jonathan
  • 23
  • 2
0
votes
3 answers

NSCoding data not saved when returning to the app?

I don't understand why previousArrays returns (null), I would like to save a class containing a bezier path and its color. The code : (after touchesEnded is called, a path is created and saved in memory. When I come back to the app with…
Paul
  • 6,108
  • 14
  • 72
  • 128