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

How to encode and decode this class

Here I want to archive and unarchive my custom class,here is the code snippet. enum Type: Int { case Fruit case Meat case Drink } class ShoppingList { var typeOne: [Type]! var typeTwo: [Type]! var typeThree: [Type]! init(coder…
tounaobun
  • 14,570
  • 9
  • 53
  • 75
0
votes
1 answer

NSCoding and ostream

Is there a better way to serialize an ObjC object than using /NSKeyedArchive? I need to distribute the object through a C++ std:ostream-like object to put on another computer. The object has over 122 members of various types... for which wants me…
Stephen Furlani
  • 6,794
  • 4
  • 31
  • 60
0
votes
1 answer

Swift NSObject subclass get BAD_ACCESS

I try to persiste my object with NSCoding but i always get BAD_ACCESS ERROR To avoid multi multiple like variable, class, i put all common variable in RObject. I think i do something wrong the the init but i don't know what. the error was thow in…
Armanoide
  • 1,248
  • 15
  • 31
0
votes
1 answer

how to retain my uitextfield values in viewController when i calling?

I have a main page having 3 textfield in my first view as i navigate to different view and return back to my first view (i.e after i enter all the values i moving to next page).I want my 3 textfield to retain its value when i go back to my main page…
Anand ios
  • 57
  • 1
  • 12
0
votes
1 answer

SceneKit and NSKeyedArchiver

I am trying to archive my SceneKit scene for saving using NSKeyedArchiver. This is so I can save the scene allowing me to restore it at a later date. I am finding that the restored scene seems to ignore/lose the SCNTransformConstraints I have added…
BassetMan
  • 461
  • 6
  • 13
0
votes
2 answers

[iPhone]Objective C, objects which do not conform to NSCoding. How to write them to a file

I am using an Objective c class, a subclass of NSObject. This class cannot be modified. I have an instance of this class that I wish to write to a file which can be retrieved and later reinstate. The object does not conform to NSCoding. To sum up, I…
123hal321
  • 2,080
  • 4
  • 24
  • 25
0
votes
3 answers

Unable to decode a NSObject in Swift

I am having a problem decoding an object after I encode it in Swift. Here is my class: class Player: NSObject, NSCoding { var score:Int = 0 init(difficulty: Int!) { super.init() } required init(coder aDecoder: NSCoder) { score =…
dhint4
  • 1,132
  • 2
  • 11
  • 25
0
votes
1 answer

What does initWithCoder initialize first-time values to?

I'm using NSCoding for a game I'm making to save stuff like a high score. My question is: What do these values get initially set as if they've never been saved before? Like in the first time running the app. It will decode the values, but there's no…
Jordy
  • 415
  • 5
  • 13
0
votes
0 answers

Export a plist in a readable fashion

I have a class following NSCoding protocols. It is designed to store an array, containing objects of a Custom-class type. I currently can retrieve and view this information in a table view, retrieving and passing the relevant objects. However, a…
invisibloom
  • 105
  • 2
  • 6
0
votes
1 answer

How to implement NSCoding

import Foundation class C: NSObject, NSCoding { var n: String = "" override init() { super.init() n = "instance of class C" } convenience init(_ name: String) { self.init() n = name } …
telliott99
  • 7,762
  • 4
  • 26
  • 26
0
votes
0 answers

decodeObjectForKey: array in Custom object returns nil

I want to store array of custom object. So I have tried encode and decode. but its not working Please check my code. - (IBAction)saveFile{ NSLog(@"%@",self.drawingView.pathArray); NSData *arrayData = [NSKeyedArchiver…
Mahavir
  • 771
  • 3
  • 9
  • 23
0
votes
1 answer

Caching data with NSCoding?

In my app, I retrieve url data from the server. As an optimization, I normalize the data by storing it into a custom class so that the data can be quickly accessed later on. However, I need to store an instance of this class locally and offline so…
Mahir
  • 1,684
  • 5
  • 31
  • 59
0
votes
2 answers

super initWIthCoder return parent type?

I think I'm missing something basic... I implemented a class with NSCoding and a child with NSCoding too, but when I call the initWithCoder of the child class , I get an InvalidArgument error. @interface Parent:…
George
  • 332
  • 1
  • 4
  • 16
0
votes
2 answers

NSCoding with a singleton subclass

I have a number of derived classes whose common base-class conforms to NSCoding. I want to be able to easily encode an NSArray holding instances of the various deriving classes. @interface Base : NSObject @end @interface DerivedSingleton…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
0
votes
1 answer

Custom NSObject iniWithCoder not called

I have a custom object, LevelContent, which contains some properties. LevelContentconforms to NSCoding, and I have implemented encodeWithCoder: and initWithCoder: methods. I save and fetch the data to Parse.com. Saving works fine like this: NSData…
imas145
  • 1,959
  • 1
  • 23
  • 32