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
-1
votes
1 answer

Implementing Hashable and NSCoding in the same class in Swift

I am having an issue trying to adopt the Hashable and NSCoding protocols within the same Swift class (or struct). Hashability and encode/decode both work independently. However, hashability is lost once an object has been restored by…
ksgg
  • 31
  • 3
-1
votes
1 answer

How to save a struct with NSCoding

How can I save my struct with NSCoding so that it doesn´t change even if the user closes the app? I would appreciate it if you could also show me how to implement the missing code correctly. UPDATE with two new functions below: Here is my code: …
Joy Lucas
  • 61
  • 1
  • 10
-1
votes
1 answer

Saving Array of Custom Objects with NSCoding Very Slow

I'm making an app that has a collection view of plants. I have Plant class that implements the NSCoding protocol so I can save them. The plants are stored in an array called plantList. var plantList = [Plant] And here's what I store in my Plant…
-1
votes
1 answer

encoding in Swift 3

I have the following code which I'm trying to put into Swift 3. The line super.encodeWithCoder(aCoder) is giving problems. Whatever I do gives an error. import Foundation class ToDo: Task { var done: Bool @objc required init(coder aDecoder:…
cpmac
  • 69
  • 8
-1
votes
1 answer

How to save whole Object in NSUserDefaults

I am using ObjectMapper to map JSON responce from my server. Here is my data model. class HomeStats: Mappable { // MARK: - Constants & Variables var todayText: String var pointsText: String var todayActivitiesText: String var totalPointsText:…
Byte
  • 629
  • 2
  • 11
  • 29
-1
votes
1 answer

How to save a custom object to NSUserDefault which contains UIImage and NSMutableArray?

In my project I need to save a custom object(Person) which have an UIImage, NSMutableArray and NSString objects. Currently I am able to encode and decode the NSString objects and archive Person to in NSUserDefault. Everything works fine except for…
Rokon
  • 355
  • 3
  • 11
-1
votes
1 answer

Saving a custom class into array inside user defaults

Lets say i have a class called Lop. then i would like to save instances of it to user defaults in some array, and also retrieve objects from this array . I have created the NSCoding method in that class and now trying to write functions to…
Curnelious
  • 1
  • 16
  • 76
  • 150
-1
votes
2 answers

How to save data from ViewController using NSCoding in Swift

I need to save data from a segued ViewController (“ScoreView.swift”) to “ScoreHistory.swift” using NSCoding. I tried but the data isn't showing up in "ScoreTableViewController.swift". What am I missing? I have this ScoreView.swift which has the…
Juma Orido
  • 481
  • 1
  • 4
  • 11
-1
votes
2 answers

How to save quiz scores using NSCoding in Swift

I am creating a simple quiz app. Whenever the user finishes the quiz, a "ScoreView" shows up which contains the following: Total Score Total Answered Questions Total Incorrect Answers I have no problem in displaying these data in the said…
Juma Orido
  • 481
  • 1
  • 4
  • 11
-1
votes
1 answer

Implementing NSCoding protocol

I'm working on a obj-c project and I want to implement the NSCoding protocol for a class, but I can't get it right. The code looks like this: #include class Object: NSObject, NSCoding { //Somecode } And I get the…
user3612623
  • 245
  • 3
  • 13
-1
votes
2 answers

create a class using NSCoding

in my first project I was creating a class using the following code: import Foundation class Rate { var currency: String! var sellRate: String! var buyRate: String! init (data: NSDictionary) { self.currency =…
Almazini
  • 1,825
  • 4
  • 25
  • 48
-1
votes
2 answers

NSCoding a c struct object which is property of a class

I have a class called Account with 6 properties and one of the properties is a c struct. I can't figure out how to use NSCoding to comply with the struct. How would I go about encoding and decoding the c struct property. The struct is the type…
blitzeus
  • 485
  • 2
  • 10
  • 28
-1
votes
1 answer

NSCoder not working with NSArray

I am trying to implement the NSCoder methods encodeWithCoder and initWithCoder for a custom object i have created which has a child array of custom objects. Both custom objects employment the above mentioned methods but after the top level object…
Jarmez De La Rocha
  • 618
  • 2
  • 9
  • 19
-1
votes
1 answer

Implementing NSCoding in Swift?

I was implementing an example posted here: http://speakobjectively.blogspot.com/2014/06/nscoding-protocol-swift-version.html?showComment=1407612816583#c9059421260580133521 I get the error "expected declaration" in two statements: documentDirectories…
Steve Rosenberg
  • 19,348
  • 7
  • 46
  • 53
-1
votes
2 answers

How do i serialize/deserialize GTLDriveFile Object into pList

I'm using google drive files in my application. Accessing files, downloading files, uploading files are working as a charm. Now I'm trying to save the GTLDriveFile information on local(pList) by using NSCoding. Can you please help me to save this…
iTag
  • 409
  • 3
  • 19
1 2 3
40
41