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

NSCoder Not Returning Values correctly

In the following code, the properties are never set correctly in the sharedInstance method, and I can't figure out why. It seems like I have the correct values though before I save it with the archiver. #import "User.h" static User…
Cocoa Nub
  • 489
  • 7
  • 20
0
votes
2 answers

NSCoding -decoder returns wrong values -iOS

I have written the following method to encode/decode data.. - (void) encode: (BOOL) encodeBool int: (NSNumber *) integer boolean:(BOOL) boolean key: (NSString *) keyStr { NSArray *paths =…
user1526474
  • 925
  • 13
  • 26
0
votes
1 answer

Loading NSTableView from unarchived data

I'm trying to implement saving of user preferences in my OS X app. I have an NSTableView which stores its data to my .plist file, but I have troubles loading same data back to my NSTableView. My model object: #import…
errata
  • 5,695
  • 10
  • 54
  • 99
0
votes
1 answer

Using UIimage NSCoding Category

so there is a solution for this, that handles backward compatibility from ios 5.1 here UIImage and NSCoding iOS 5.1 My problem is...it does not seem to work, at this point if (![UIImage conformsToProtocol:@protocol(NSCoding)]) { } It skips right…
Genhain
  • 1,937
  • 1
  • 19
  • 38
0
votes
1 answer

Saving & deleting saved objects IOS

I have a fairly simple class that represents a game being created by a player for another player, before they game is sent to the other player by the server I would like to implement a sort of persistence in case something goes wrong i.e a crash. So…
Genhain
  • 1,937
  • 1
  • 19
  • 38
0
votes
1 answer

What is a best way to save user interface objects iOS

I have an UIScrollView object that contain other views. There are UIViewController(s) that user can create in runtime and puts they views on UIScrollView. In its turn they store also different view. So I suppose that I can use NSCoding for storing…
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
0
votes
1 answer

Some of NSCoding variables are NOT retrieved

I am using an NSData to store an object for later use. It has quite a few NSStrings and I need to pull it out of an object. For some reason, only some of the NSStrings are stored and some others get zeroed out! I was thinking it must be something…
Ted
  • 3,805
  • 14
  • 56
  • 98
0
votes
1 answer

Serializing a custom object to a PLIST

I want to be able to take an object and write out all its properties to a PLIST. I got so far with this: // Get the properties of the parent class NSMutableArray *contentViewPropertyNames = [self propertyNamesOfObject:[contentView superclass]]; //…
Magic Bullet Dave
  • 9,006
  • 10
  • 51
  • 81
0
votes
1 answer

Key not found in an NSKeyedUnarchiver object

I usually encode my data in a NSFileWrapper like this (I leave out the NSFileWrapper bit): -(NSData*)encodeObject:(id)o { @autoreleasepool { NSMutableData *data = [NSMutableData data]; …
n.evermind
  • 11,944
  • 19
  • 78
  • 122
0
votes
2 answers

Objective-C and NSCoding primative data type just like the old C code

I have some old C code that looks like this: #include #include main() { FILE *output; struct socket_cpacket { char type; /* CP_SOCKET */ char version; …
Bob Tanner
  • 250
  • 1
  • 2
  • 5
0
votes
2 answers

Saving custom objects to a plist with NSCoder

So, I've realised that I need to use NSCoding to save my custom objects to a plist. The part I'm struggling with is exactly how I do that after I've implemented the initWithCoder and encodeWithCoder methods. They return id and void respectively, so…
Luke
  • 9,512
  • 15
  • 82
  • 146
0
votes
1 answer

CoreData: Large quantity of entities or store an array as Transformable?

I am making a game where every creature can have 3 attacks and every attack can have many effects at the same time. I'm using CoreData to hold all of the data. A basic example of what my problem is can be seen with three entities: Creature:…
gabriellanata
  • 3,946
  • 2
  • 21
  • 27
0
votes
2 answers

iOS NSKeyedUnarchiver calling singleton getter

I have a singleton class that will initialize it's data from a web service then save itself to a file (using NSCoding and NSKeyedUnarchiver) so I can just initialize this file instead of pulling all the data from the web again. Because it's a…
javajavajavajavajava
  • 1,223
  • 2
  • 12
  • 20
0
votes
1 answer

Is it possible to reuse an NSKeyedUnarchiver?

I'm working on an iOS game and I'm using the NSCoding protocol to save my levels in my editor and to load them in game. I was wondering if it was possible to somehow reuse an NSKeyedUnarchiver after it's been used to load the level. For instance…
DrummerB
  • 39,814
  • 12
  • 105
  • 142
0
votes
1 answer

Split Data for NSKeyedArchiver and NSKeyedUnarchiver

Edit (2012/10/22): Restating this question in hopefully clearer terms. Essentially, what I'm looking for is some NSCoder that can (un)archive between multiple locations. Some of the encoded objects primitives should be saved in location A while…
Ncat
  • 417
  • 3
  • 10