Questions tagged [nscoder]

The NSCoder abstract class declares the interface used by concrete subclasses to transfer objects and other Objective-C/Swift data items between memory and some other format.

189 questions
0
votes
0 answers

Swift NSCoder Not Working For Double Variable

I'm restoring the state of my app and am storing a few variables using the NSCoder in Xcode 10.1. The NSCoder is fine at storing strings and other variable types, but won't allow me to store Doubles. I've tried numerous scenarios but it just doesn't…
dgee4
  • 381
  • 3
  • 16
0
votes
0 answers

Encoding and decoding SKSpriteNode

I am a little bit confused about how to decode an SKSpriteNode. I have the following SKSpriteNode class: class Person : SKSpriteNode { var gender : Gender var age : Age var positionX : CGFloat! var positionY : CGFloat! let frontTexture :…
Igor Tupitsyn
  • 1,193
  • 3
  • 18
  • 45
0
votes
2 answers

Crash while decoding with NSCoder

I have two model classes for saving data, I am getting crash while decoding the data. The first class: class User: NSObject,NSCoding, Mappable { var authenticationToken: String? var _id: String? var email: String? var…
Abhishek Master
  • 192
  • 2
  • 19
0
votes
1 answer

Save a struct with NSCoding

I want to save the following data: class Book: NSObject, NSCoding { var title: String var chapter: [Chapter] struct Chapter { var chapTitle: String var texte: [Texte] } struct Texte { var description: String var texte: [String] …
0
votes
0 answers

Change the object after being returned in Swift

NSKeyedUnarchiver which is a concrete subclass of NSCoder works like magic. Please take a look at this example: I have 2 classes, Person and CreditCard class Person: NSObject, NSCoding { var creditCard: CreditCard init(coder aDecoder:…
Edward Anthony
  • 3,354
  • 3
  • 25
  • 40
0
votes
0 answers

NSCoding fails during optional property assignment

Consider following example class: class C: NSObject, NSCoding { var b: Bool? // optional parameter // designated initializer init (b: Bool){...} // initializer by NSCoding protocol required init?(coder aDecoder: NSCoder) { …
Ruben Kazumov
  • 3,803
  • 2
  • 26
  • 39
0
votes
0 answers

Best way to persist an Array of Custom Objects in Swift on iOS

My current solution to this problem is creating a class that implements NSObject and NSCoder and using that to encode and decode my Array of Plant Objects (Plant consists of two strings and a UIImage). It seems unnecessary that I have to create a…
Gabe Spound
  • 568
  • 5
  • 28
0
votes
0 answers

Xcode - Access persistent data from simulator (NSCoder)

I am storing persistent data in my application using NSCoder like below: class UserNotification: NSObject, NSCoding { var message: String! init(message: String) { self.message = message } required convenience init(coder…
drante
  • 129
  • 9
0
votes
1 answer

How to find the base class which called the Decoder initialiser

I have a BaseView class which is inherited from UIView like: @IBDesignable class BaseView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) …
Mina
  • 2,167
  • 2
  • 25
  • 32
0
votes
4 answers

Can't Call function in another class due to initialiser

I am trying to call a function from TheTimer class from my MainClass class. However, in the TheTimer class there is a required init, and when I try and call the Start function from the TheTimer class (I call it from the MainClass class) it throws…
RufusV
  • 408
  • 3
  • 17
0
votes
0 answers

Wierd NSKeyedArchiver behavior after updating to XCode 9

I had an app which worked perfect with Xcode 8. Now I'm preparing some minor update and faced with unexpected behavior of NSKeyedArchiver. Below the code which worked with no issues before updating to Xcode 9: func saveChecklist(_ checklist :…
0
votes
0 answers

Choosing NSCoding over CoreData for storing and retrieving around 1000 images and backup to iCloud

Here's a rough representation of the data structure: [ "recipeName" : [ "ingredients" : [String], "rating" : Int, "picture" : UIImage, "url" : URL ] ] Since storing large amount of images would require all the data to be loaded in memory while…
as diu
  • 1,010
  • 15
  • 31
0
votes
0 answers

NSCoder of an array of custom class

I am using UserDefaults to store data, specifically an array of type Workout. In the Workout class is an array of type Exercise. When I call the save function to persist the data, the code crashes when encoding the Exercise array. What am I doing…
shavavo
  • 65
  • 1
  • 6
0
votes
1 answer

Which NSCoder does .pbxproj format use?

Inside the .xcodeproj bundle, main project data is actually stored in the .pbxproj file. It is quite obviously an archived dictionary, but I have not been able to find which coder did Apple use? Is it a custom subclass of NSCoder, or is it…
Ivan Vučica
  • 9,529
  • 9
  • 60
  • 111
0
votes
1 answer

Extended UIButton testing with zombies stops in super.init(coder: aDecoder)

Initializing UIButton makes it to stop in super.init line testing with zombies. Clicking continue button runs without problem. Why ? How can I see the reason to stop there ? required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) …
Fischer
  • 1,513
  • 4
  • 17
  • 38