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

Encode Array with NSCoder

I have a User Class that uses a saveuser() method whenever the application terminates. The User has two Arrays of Custom Classes that sub-class NSObject. Here is my encode method. func encode(with aCoder: NSCoder) { …
Gabe Spound
  • 146
  • 2
  • 14
0
votes
0 answers

Exception for NSKeyedUnarchiver, but everything works

I'm getting odd exception: -[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver? when deserializing object that was previously archived with NSKeyedArchiver and transferred over…
peetonn
  • 2,942
  • 4
  • 32
  • 49
0
votes
2 answers

NSCoder fail to decode Float

I have define a class with [String] and Float properties, it's working fine with the encoding process with NSCoder, but it's always fail with decoding. I have add the guard let into the code, and located it's the problem of the Float $. I have no…
CY.L
  • 35
  • 1
  • 5
0
votes
2 answers

Encode enum with NSCoding

I am implementing NSCoding in my library, but I need to serialize an enum variable and I can't pass it in for the function that takes AnyObject?. How would this be done in Swift? Here is my enum: enum ServerType { case PC case PE } Also,…
Bennett
  • 1,007
  • 4
  • 15
  • 29
0
votes
1 answer

Loading Game State with NSCoder?

How can I load the items I saved (or tried to save) with NSCoder? I am using the cocos2d framework. Here's a method I made to save things. -(void)save: (NSCoder *) coder { [coder encodeObject:[NSNumber numberWithInt:level]]; [coder…
Joethemonkey101
  • 45
  • 2
  • 11
0
votes
1 answer

iOS: best way to cache downloaded rss messages

I'm implementing what essential amounts to an RSS reader for iPhone. I download a bunch of short messages and display them to the user in a list. Each message is encapsulated in a MyMessage object that contains the title, the body, url, etc. I want…
Wise Shepherd
  • 2,228
  • 4
  • 31
  • 43
0
votes
1 answer

My Objects data member (NSString *) value contaminated '0x7fc0ab73d040' after UnArchiving from NSData

I am in such a hectic situation right now for almost a whole day. Please see and tell if you can help... Here I am using my CustomObjects ('Alarm Object' implemented with NSCoder), saving it to NSUserDefaults AlarmObject has one property (NSString…
Sulman Malik
  • 135
  • 1
  • 1
  • 7
0
votes
1 answer

Is it possible to access a UIView's properties (e.g. frame) in init(coder:)?

I am trying to understand how to properly used NSCoder when subclassing UIView: required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } I am wondering whether it is possible to access any properties that aDecoder might carry. I…
nburk
  • 22,409
  • 18
  • 87
  • 132
0
votes
1 answer

NSUserDefaults for custom object with other custom class variables

I have tried look at the other answers regarding NSUserDefaults, but so far they haven't helped. I'm trying to save a Player into NSUserDefaults, but the Player class also has two variables for the custom classes Pokemon and Items. How do I save and…
impo
  • 747
  • 1
  • 11
  • 37
0
votes
2 answers

How to call a function from a different view controller with different classes

When you press on the screen im trying to get a function that Is in a different view Controller to be called usaully i would just do the viewControllerFuncIsIn().NameOfFunc() but because the view controller class that has the function im trying…
Hunter
  • 1,321
  • 4
  • 18
  • 34
0
votes
1 answer

How to convert Class types?

I'm trying to figure out how to convert class type so that I can go from my SKScene which is 'self' to my SCNScene which is GamePlay. And basically perform a scene normal scene transition. Code: let scene = GamePlay(coder:NSCoder()) let transition…
Hunter
  • 1,321
  • 4
  • 18
  • 34
0
votes
3 answers

'self' used before self.init call error while using NSCoding on a custom class

I'm trying to encode a custom class so I can save it using NSKeyedArchiver.archivedDataWithRootObject but when I try to conform to the NSCoding protocol, I get this error : 'self' used before self.init. Here is my code: class MemberRewardsInfo:…
SwiftyJD
  • 5,257
  • 7
  • 41
  • 92
0
votes
0 answers

swift NSCoder dont decode in widget

I have a code that is executed in the host application and widget. All works in the main application, but one line in the widget - no required init(coder aDecoder: NSCoder) { name = aDecoder.decodeObject(forKey: "Name") as! String ip[0] = …
MacSergey
  • 15
  • 7
0
votes
1 answer

Does this write or read an array?

[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"]; I'm trying to figure out how to save and load an array using NSUser Defaults. I already have the NSCoding delegate methods defined, just need to know the actual commands…
node ninja
  • 31,796
  • 59
  • 166
  • 254
0
votes
2 answers

How can I clone a NSCoding compliant object into a subclass of it?

I have a custom subclass of NSPopUpButtonCell so that I can overwrite its drawBezelWithFrame:inView: method. Currently, I have to create a fresh instance using initTextCell:pullsDown: and then copy all its properties by hand. That's rather tedious…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149