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
7
votes
3 answers

What is the new pattern for releasing self with automatic reference counting?

Using the NSObject method -(id)awakeAfterUsingCoder:(NSCoder *)decoder as an example, the documentation says: Allows an object, after being decoded, to substitute another object for itself. For example, an object that represents a font might,…
6
votes
2 answers

Easy way to do NSCoder enabled class

I have tons of objects which I want to save for offline use. Currently I use create NSCoder compliant classes for the objects and coded data to file to be available offline. So in the .h I introduce the objects: @interface MyClass :…
MapaX
  • 98
  • 1
  • 7
6
votes
2 answers

When does initWithCoder get called?

This will load an array - (id)initWithCoder:(NSCoder*) coder { self = [super initWithCoder: coder]; if (self) { myArray=[coder decodeObjectForKey:@"myArray"]; } return self; } What is the code that will call this function so…
node ninja
  • 31,796
  • 59
  • 166
  • 254
6
votes
3 answers

Can NSManagedObject conform to NSCoding

I need to transfer a single object across device. Right now I am converting my NSManagedObject to a dictionary , archiving it and sending as NSData. Upon receiving I am unarchiving it. But I would really like to transfer the NSManagedObject itself…
darshansonde
  • 491
  • 1
  • 8
  • 13
5
votes
1 answer

NSKeyedArchiver returning nil Swift 4.2

let lessons = Lessons(definition: "testo", photo: url) SaveUtil.saveLessons(lessons: lessons!) let x = SaveUtil.loadLessons() So everything compiles and runs but x is nil....I'm trying to make this ios12/swift 4.2 compliant but no idea what is…
hunterp
  • 15,716
  • 18
  • 63
  • 115
5
votes
2 answers

UITableViewCell as UIView from XIB

I have CustomTableViewClass in XIB, adding it to UITableView like class RestaurantsTableView: UITableView { override func awakeFromNib() { self.register(UINib(nibName: "RestaurantTableViewCell", bundle: nil), forCellReuseIdentifier:…
JuicyFruit
  • 2,638
  • 2
  • 18
  • 35
5
votes
1 answer

When does encodeWithCoder get called?

This will save an array (I think). - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:myArray forKey:@"myArray"]; } Do I have to directly call this method when I want to save an array or do I have to do something else?
node ninja
  • 31,796
  • 59
  • 166
  • 254
5
votes
1 answer

May I use NSCoder::encodeInteger:forKey: and decodeIntegerForKey: methods with argument of type NSUInteger?

I need to encode and decode property of type NSUInteger with NSCoder. Is it safe to use NSCoder::encodeInteger:forKey: and NSCoder::decodeIntegerForKey: methods for that? The other way around that comes to my mind is to wrap the unsigned integer…
Rasto
  • 17,204
  • 47
  • 154
  • 245
4
votes
1 answer

NSCoder - Encoding an Array, with multiple levels of nested arrays

I have a mainObjectArray (NSMutableArray) which is populated with instances of a custom class. Each instance is itself an array, and objects in each array are NSDates, NSStrings, BOOL, and more arrays containing similar objects. What I haven't been…
Charl
  • 85
  • 1
  • 8
4
votes
1 answer

NSKeyedArchiver encode only part of an array

I have a list of objects that can sometimes change, and I want to keep a persistent cache on the device whenever the app is closed or move to the background. Most of the objects in the list will not change, so i was wondering what is the best way to…
Adam
  • 81
  • 1
  • 2
4
votes
1 answer

Is there a way to encode and decode the closures?

For some reason, I need to serialize a class object that contains several closure fields. Like this: import Foundation class Foo: NSObject, NSCoding { var bar: (() -> Void) override init() { bar = {} } required init(coder…
Aofei Sheng
  • 121
  • 6
4
votes
2 answers

Save own Class with NSCoder

I'm trying to store some custom class/data to a file in my iPhone/iPad app. I have a Class RSHighscoreList @interface RSHighscoreList : NSObject { NSMutableArray *list; } which contains objects of RSHighscore in the list @interface RSHighscore…
Stef
  • 593
  • 3
  • 10
  • 23
4
votes
1 answer

Swift - NSCoder and PHAsset

I have this code: import Foundation import Photos class PostItem: NSObject, NSCoding { var postDate: String? var postTitle: String? var postText: String? var postImages: [PHAsset]? func encodeWithCoder(aCoder: NSCoder) { …
4
votes
3 answers

Debuging problems - Values are hidden

I need some ideea about what can be he cause of my problem . I have a source code and i want to make some debug on it , but i can't see the variables. For example : NSArray *oldSavedArray = [NSKeyedUnarchiver…
Adina Marin
  • 663
  • 1
  • 4
  • 15
4
votes
3 answers

Simple Swift class does not compile

My simple class, ClassWithOneArray, produces this error: Bitcast requires both operands to be pointer or neither %19 = bitcast i64 %18 to %objc_object*, !dbg !470 LLVM ERROR: Broken function found, compilation aborted! Command …
Narwhal
  • 744
  • 1
  • 8
  • 22
1
2
3
12 13