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

Write Object to Plist using NSCoding and NSCoder

I've created a class that conforms to NSCoding - (id) initWithCoder:(NSCoder *)aDecoder { self = [super init]; if (self) { self.name = [aDecoder decodeObjectForKey:@"name"]; self.type = [aDecoder decodeObjectForKey:@"type"]; …
nstein
  • 339
  • 2
  • 14
0
votes
1 answer

Using NSCoder for restoration between views (viewWillAppear / viewWillDisappear)

I am wondering if there is a way to maintain user input when navigating back and forth to my main menu using the UINavigationBar back arrow using NSCoder. I am currently using NSCoder to maintain this data during background/terminate/restart and…
0
votes
0 answers

Setting initial NSUserDefaults has killed my encode/decode state restoration

I have set up state restoration so that my application retains user input, button states, etc. on background/terminate/restart. I am saving a bunch of them, so I will only include partial clode for what this looks like in my viewcontroller.m…
C_Dub
  • 77
  • 11
0
votes
0 answers

Save NSLayoutConstraints to plist file

I have implemented auto layout pretty well in each and every project I have done till now. So I have a very good understanding but I got trapped when I wanted to save auto layout objects to a plist file. Currently I have written below…
Geekoder
  • 1,531
  • 10
  • 21
0
votes
1 answer

Archiving objects within objects in objective-c

Thankyou for reading, PS: I am a beginner so I am not too good at this unfortunetaly, but any help would be very appreciated So basically I want to archive a big array which contains Account objects, which they themselves contain: 1.a username in…
jundl77
  • 476
  • 2
  • 15
0
votes
2 answers

Objective C decodeBoolForKey not compatible with BOOL

So I have an NSObject which implements NSCoding. In my decoder method it needs to retrieve a BOOL that belongs to the class among other properties. -(id)initWithCoder:(NSCoder *)decoder { self = [super init]; if (self) { [self…
willbattel
  • 1,040
  • 1
  • 10
  • 37
0
votes
1 answer

Encoding NSMutableArrays give error with NSCoding

When I try to encode my custom object whit an NSMutableArray, I always get this exception: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'cannot encode (void *) value: <2063e916>' What could cause this? The…
Endanke
  • 867
  • 13
  • 24
0
votes
2 answers

NsmutableArray don't succeded to save at close of app

Hello I can not save locally where I have to save an array of strings, I add that this array must be saved when closing the application for iOS and the reopening needs to be recharged, I found thousands of guides online but none are very specific,…
Filippo
  • 23
  • 6
0
votes
1 answer

NSCoder - Only Called On Object instantiation

I have set up a class that conforms to NSCoding, and works as expected when I first create the object. It is essentially the same set up as this The problem I am having is that the properties of the object when changed are not kept. For example, Foo…
DogCoffee
  • 19,820
  • 10
  • 87
  • 120
0
votes
1 answer

Subclassed CCSpriteBatchNode object is nil

I subclassed CCSpriteBatchNode to make an object that conforms to NSCoding. I was mainly interested in the string name of the CCSpriteBatchNode. After setting break points I realized that the object's string name is always nil. I have a feeling it…
0
votes
1 answer

Custom objective-c class doesn't encode

I have a custom class that conforms to the NSCoding protocol but still refuses to encode when I call write to file. @implementation PXLevel - (id)initWithName:(NSString *)name andArray:(NSMutableArray *)map { self = [super init]; self.name…
evilseto
  • 29
  • 6
0
votes
1 answer

I need some help archiving an NSArray to hold some values and add/delete them later

I am doing an app as a starter to get some experience, I am making a simple app that stores assignments in a table view. So I have a table view as a main view and a plus button that pulls up a modal view controller that allows the user to enter…
AbdelElrafa
  • 881
  • 8
  • 16
0
votes
1 answer

NSCoding Prebundle Data

I am using NSCoding to save a serialized list of my object. This object's successfully saved in the path: /var/mobile/Applications/F923C87-360D-4B429-B2E9-CAE121009ECE5/Documents/feed_file And I can get the object successfully when the app…
Sqlumee
  • 1
  • 1
0
votes
1 answer

iOS and NSCoding: is this the correct way to encode an NSMutableArray with custom objects?

I have this class with an NSMutableArray of custom Cocos2d objects implementing the NSCoding protocol. @interface PlayerData : NSObject { } @property (readwrite, nonatomic) NSMutableArray *levelsStars; //Where levelsStars is filled with…
mm24
  • 9,280
  • 12
  • 75
  • 170
0
votes
1 answer

Adopting NSSecureCoding with opaque types

I have an Objective-C class that needs to adopt NSSecureCoding for transport across an XPC connection. The class has a couple properties that are opaque types (dispatch_queue_t and dispatch_group_t). How would I go about implementing -initWithCoder:…
Andrew
  • 7,630
  • 3
  • 42
  • 51