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

Swift compiler error: Bitcast requires both operands to be pointer or neither

I am getting the above compiler error on the following class: class Log: NSObject, NSCoding { var targetHoursPerWeek: Double var weeksLog: Double[] // Serialization keys that are using to implement NSCoding. struct SerializationKey { static…
jxxcarlson
  • 223
  • 3
  • 13
0
votes
2 answers

initWithCoder: get called without import the category

A UIImageView category has been defined in HDScrollview.h. It is not imported in GoodDetailViewController.m, But when the code cell = [[[NSBundle mainBundle] loadNibNamed: CellIdentifier owner: self options: nil] lastObject]; runs,…
lu yuan
  • 7,207
  • 9
  • 44
  • 78
0
votes
1 answer

iOS - UIDocument Versioning

I want to add versioning to my UIDocument local storage setup. In each of my classes that needs to be stored locally, I overwrite encodeWithCoder: and initWithCoder: like so: #define kLovelyString @"LovelyString" - (void)encodeWithCoder:(NSCoder…
rizzes
  • 1,532
  • 20
  • 33
0
votes
1 answer

NSCoding - Protocol Methods (encodeWithCoder, initWithCoder) Repeated Code

I am using NSCoding for local data persistence. I have a bunch of model classes that need to be stored locally. I've been implementing encodeWithCoder and initWithCoder protocol methods for hours. But it's not actually "coding", it's just repeating…
rizzes
  • 1,532
  • 20
  • 33
0
votes
1 answer

Error with encodeWithCoder

Hi I am using GoogleMaps in my ios app and there is a part where I have to save the map marker positions in the CoreData. I am using the code GMSMarker *marker = [GMSMarker markerWithPosition:position]; marker.map = _mapView; [waypoints_…
0
votes
0 answers

Archiving (NSCoding) when using cocos2d - EXC_BAD_ACCESS

I'm making a game using Cocos2d-iphone 2.1, and have encountered an error with NSCoding unarchiving implementation. I've used the same pattern in my previous projects (made with UIKit), and everything worked perfetly. While when I'm implementing…
Andrey
  • 13
  • 3
0
votes
1 answer

NSKeyedArchiver would not save or load objects

So I have an array with some custom classes: NSMutableArray With Games (FirstViewcontroller) -Game with Dices (Game.m) -- Dices With Options (Dices.m) In each custom class i've setter the encode and decode up: -(void)encodeWithCoder:(NSCoder…
Kets
  • 438
  • 2
  • 8
  • 24
0
votes
2 answers

NSKeyedArchiver saving iOS

I'm trying to save for the first time. Made my application, and now going to save data and load on startup and close. Looked into NSKeyedArchiver and added the two methods from the NSCoding to all my custom classes: -(void)encodeWithCoder:(NSCoder…
Kets
  • 438
  • 2
  • 8
  • 24
0
votes
0 answers

Save Custom object (it has some sub object) collection to pList?

Folks, I'm trying to array of objects to pList by using NSCoder class. I can save some direct objects to the plist. For Ex: I've class called 'ExClass' with Sample(NSString) property. Now i could save a collection of 'ExClass' object to pList…
0
votes
1 answer

Serialization of Objects in objective c without NSCoder

I'm working with a project that requires me to serialize my objects in order to send them... Apple says that because space is limited I should serialize the objects without using NSCoding or NSCoder because there is no way of predicting the end size…
Matt Zera
  • 465
  • 3
  • 12
0
votes
2 answers

Implementing NSCoding protocol to send object over to the Java based server

I have asked a similar question a couple of days ago... While I have made some progress, I still cant seem to make it work. Here is what I got up till now: customWriteableObj.h: @interface customWriteableObj : NSObject @property…
Marci-man
  • 2,113
  • 3
  • 28
  • 76
0
votes
3 answers

How do I save/load data in my application using NSCoding?

Yes, I've looked through the numerous questions similar to this that were asked already; however, I still did not quite understand what was going on or at least I couldn't figure out how to do it in my application. So basically my "practice" app has…
Tony
  • 31
  • 7
0
votes
3 answers

Encoding data in an instance of one class and decoding the data in an instance of a different class

I am new to Objective-C and Cocoa Touch. I have two view controllers, one an instance of one class and the second an instance of a different class. Using I have encoded data used in the second view controller. I would like to set the data to nil…
Jim Botts
  • 59
  • 1
  • 10
0
votes
1 answer

How simulate update of iOS application

My application have several classes that implemented NSCoding protocol. And the app save instances of these classes to the file system In near future I will publish a new version of my application. This app will include the changed logic of - (void)…
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
0
votes
1 answer

Unable to save table data via NSCoding

I have an array of Objects (containing an item name and a creation date) used to display table data. I want to save this array using NSCoding protocol. I call my saveDataToDisk method every time a "submit" button is pressed to submit a new table…
somethingstrang
  • 1,079
  • 2
  • 14
  • 29