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.
Questions tagged [nscoder]
189 questions
4
votes
2 answers
Sample (preferably simple) subclass of NSCoder?
I'm trying to create a subclass of NSCoder, but I really don't know where to start. Apple's documentation lists which methods are required, but not much else. Maybe my Google-fu is weak, but I can't find any examples of an implementation of, e.g.…

andyvn22
- 14,696
- 1
- 52
- 74
3
votes
1 answer
What file extension should be applied to NSCoder binary file format?
When using NSCoder and NSKeyedArchiver, I understand the data is stored in binary format. Therefore, what is the most appropriate file extension for a storage file? Many tutorials use .plist, but I believe this should be text property lists ~ key /…

Paul Williams
- 386
- 7
- 20
3
votes
3 answers
How do NSCoder and/or NSKeyedUnarchiver handle multiple decodings of the same object?
I was wondering how NSCoder would handle an object that was shared and encoded by multiple objects the next time it was decoded. Will it make two copies of the object, or will one object be decoded and shared between all other objects that decode…

Eric L
- 640
- 6
- 20
3
votes
2 answers
Objective-C struct property pointer cannot be made via self.prop?
I've just encountered a little surprise whilst writing NSCoder support into a class. I have a class A which contains an exposed 'color' property of an rgb struct type. I have another class B which extends A.
To encode the color property within class…

KomodoDave
- 7,239
- 10
- 60
- 92
3
votes
2 answers
How to save a NSMutableArray (containing other arrays) to file
This has been asked before and people have given very good instructions on how to do this, e.g. here.
However, I was wondering if I really need to work with NSCoder if I simply wanted to save one NSMutableArray (containing various instances of…

n.evermind
- 11,944
- 19
- 78
- 122
3
votes
1 answer
NSKeyedUnarchiver data in wrong format
I'm using ARKit and GameKitMatches so I can't use Codable (afaik) because MCPeerID as well as ARWorldMap aren't codable, to get that out of the way first.
So I'm using NSCoding and NSSecureCoding but for some reason I always catch the error:
The…

thisIsTheFoxe
- 1,584
- 1
- 9
- 30
3
votes
1 answer
Saving a UIView for next launch (not as an image)
I am building an app with several UIViews which are generated dynamically, based on user inputs. These UIViews may contain labels, images and text. They take some time to generate so I would like the user to be able to load them up quickly on…

stipoy
- 251
- 2
- 5
3
votes
1 answer
NSCoder decodeDouble of optional value
The decodeDouble on NSCoder returns a non-optional value, but I would like to identify whether a value was nil before it was encoded.
This is my scenario:
var optionalDouble: Double? = nil
func encode(with aCoder: NSCoder) {
if let…

MarkHim
- 5,686
- 5
- 32
- 64
3
votes
1 answer
How to convert NSKeyedArchiver objects over new versions
I just released an app to the app store and one of my patrons let me know that I should change the data type that I was previously storing as an Integer, using the NSKeyedArchiver, to a Double.
Easy enough to change the app's data model but when I…

John Luke Garofalo
- 130
- 8
3
votes
1 answer
Encode and Decode enum in Swift 1.2
I have a enum in my Swift class and a variable declared. I need to encode and decode it using NSCoder. There are a lot of questions about this saying that I should use rawValue. Enum is declared the following way:
enum ConnectionType {
case…

Nikita Zernov
- 5,465
- 6
- 39
- 70
3
votes
1 answer
Instantiating UIViewController Without A Storyboard Or xib File
I have been looking for a a way to instantiate a custom UIViewController class which is not attached to a storyboard or xib file.
Naturally, when I try to initialize the UIViewController it's expecting an NSCoder object.
However I have no idea where…

Aggressor
- 13,323
- 24
- 103
- 182
3
votes
2 answers
How to call initWithCoder?
I have UIViewController and UIView subclass (lets say ViewSubClass). I am using story board. In mainStoryBoard.storyBord , I put one UIView and set custom class ViewSubClass. Now I do not want to create instance of ViewSubClass in UIViewController…

h999
- 395
- 1
- 5
- 21
3
votes
1 answer
iOS: Name of image used in XIB
Is there any way to find out in code name of image was used in XIB for eg background for a button?
Let say I have xib with button which has property Background (for State Config: Default) set as "button.png", button has an IBOutlet eg myButton. When…

majuszt
- 75
- 5
3
votes
1 answer
What’s the difference beetween NSCoder’s encodeObject: and encodeObject:forkey:?
In NSCoder, you can call encodeObject: and encodeObject:forkey:. And this for many data types. What is the difference beetween those calls? How to use them? Why isn't there a encodeDataObject:forkey: or encodePropertyList:forKey:?

Oliver
- 23,072
- 33
- 138
- 230
3
votes
1 answer
How to call encodeWithCoder
Possibly a nooby question - how is encodeWithCoder called? I need to use this to save objects in files on the iphone, I am just unsure of how it is actually called. Do I have to manually call it? If so, what do I use as input for the NScoder…

Fitzy
- 1,871
- 6
- 23
- 40