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
2
votes
2 answers
Subclass NSCoder - failable initializer or not?
I am using Xcode 7.2 beta.
I am trying to make a class model to conform to NSCoding.
class Person: NSObject, NSCoding {
Xcode wants me to provide implementation for this:
required init?(coder aDecoder: NSCoder)
I saw that I can remove the "?",…

Laura Calinoiu
- 704
- 1
- 8
- 24
2
votes
0 answers
Trouble decoding with NSKeyedUnarchiver
I am writing an app targeted at iOS 4.0 on XCode 3.2.3 where I store some data when the app closes using NSCoder protocol. Saving seems to work fine, the problem is retrieving the data from the saved files. My save method looks like…

mag725
- 695
- 2
- 9
- 22
2
votes
0 answers
initWithCoder and encodeWithEncoder hell. Can this be simplified?
With dozens of models with dozens of properties each, all able to be saved to disk using the NSCoder protocol and NSKeyed(Un)archiver, it's a lot of work to create and maintain models for my iOS application. With a dozen of properties for one model,…

Rebel Designer
- 235
- 4
- 12
2
votes
1 answer
Swift - Why init(coder) is required in AFHTTPSessionManager?
I'm not very experienced in iOS development. While making subclass of AFHTTPSessionManager XCode suggested me to include required init(coder):
import UIKit
let _sharedAPIManager = APIManager(baseURL: NSURL(string: API_URL)!)
class APIManager:…

Kosmetika
- 20,774
- 37
- 108
- 172
2
votes
2 answers
What do the words before variables mean in init()s?
Sorry for terrible question, but I've been reading the swift book and following tutorials, and I've found about this NSCoder protocol and disabling it and whatnot.
required init(coder aDecoder: NSCoder) {
fatalError("not been implemented")
}
I…

Jaxkr
- 1,236
- 2
- 13
- 33
2
votes
1 answer
Swift required init NSCoder constructor
I have the following class representing a button in my iOS 8 custom keyboard:
internal class KeyButton: UIButton {
required init(char: Character) {
super.init()
}
required init(coder aDecoder: NSCoder) {
…

jkigel
- 1,592
- 6
- 28
- 49
2
votes
1 answer
Does the iOS simulator clear NSCoder-written environment on every restart?
When saving and loading using NSCoder in XCode, I can't seem to save the application state and load it back.
What I'm trying to accomplish is to save the app state and then reload it every time I restart. In essence, continuing where I left…

kfmfe04
- 14,936
- 14
- 74
- 140
2
votes
2 answers
iphone / objective C / how to encode a double[] for archiving
I am using double[] instead of NSArray. Would anyone know how to encode it for archiving

Amarsh
- 11,214
- 18
- 53
- 78
2
votes
0 answers
How to get file's owner from NSCoder
I'm trying to embed a custom UIView subclass using interface builder into a nib, but the custom view's nib is in another nib. So I use awakeAfterUsingCoder:(NSCoder *)aDecoder to dynamically select the correct nib for the custom UIView. Only issue…

Awesome-o
- 2,002
- 1
- 26
- 38
2
votes
0 answers
NSMutableArray subclass not calling subclass's initWithCoder when unarchiving
I have a subclass of NSMutableArray that contains various configuration information along with it's normal array data.
When I archive the subclass, the subclass's encodeWithCoder method is called, but when I unarchive it, the initWithCoder is never…

Mike M
- 4,358
- 1
- 28
- 48
2
votes
1 answer
Which coder should I use to code a long property using NSCoder?
I have an object I must encode using encodewithcoder but it's a 'long' number and I'm not sure if I must encode it like a simple int, a int32 or a int64. Apple's documentation doesn't seems to be useful for me to figure out since it never refers to…

rmvz3
- 1,133
- 2
- 16
- 27
2
votes
2 answers
How to save/archive an NSMutableArray containing custom objects?
I have an NSMutableArray *recordsArray, the keys are NSStrings, and the values are a custom object:
@interface DictRecord : NSObject{
}
@property (nonatomic, retain) NSString* word;
@property (nonatomic, retain) NSString *wordStatus;
Cocoa: How…

Joey FourSheds
- 479
- 1
- 7
- 18
2
votes
2 answers
How Do I Manage Memory of A Decoded Object Returned From NSCoder?
I have brought back a root object from being encoded with NSCoder and have no idea how to memory manage this returned object. I have surrounded it with an autorelease pool, but the object doesn't go out with the pool. Code Here, See line 289 Line…

cxx6xxc
- 171
- 8
2
votes
0 answers
Determine class while decoding object
For dealing with (a couple of) legacy communication protocols I try to subclass NSCoder. While the coding works fine, I have some issues with decoding: The protocol does not keep any type information, but a receiver "knows" the structure of a…

Matthias
- 8,018
- 2
- 27
- 53
1
vote
2 answers
What is the use of NSCoder in initWithCoder:? (Cocoa and Cocoa Touch)
Whats the role of NSCoder here?
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self)
{
}
return self;
}

suhail
- 19
- 4