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
1 answer
Unarchiving UIImageView with subviews
I'm going a bit crazy trying to archive and unarchive a UIImageView which has number of subviews which are custom views derived from UIImageView. Here's what I've done:
Add a category to the project to allow for the fact that UIImage does not…

beev
- 1,197
- 2
- 16
- 33
2
votes
2 answers
When subclassing NSCoder, would I need to subclass collection classes (i.e:NSArray,NSDictionary) aswell?
I'm exploring the idea of subclassing NSCoder to read/write a proprietary file format. I'm starting to believe this might also require me to subclass NSArray and NSDictionary to override encodeWithCoder: to ensure they are encoded properly:
-…
user1040049
2
votes
1 answer
NSCoder for unsigned integers with swift
In my swift app, I really need to store a UInt32 value and retrieve it using NSCoder.
The issue is, there are methods for signed integers :
coder.decodeInteger()
coder.decodeInt32()
coder.decodeInt64()
but not for unsigned integers.
Also, casting…

Anco34
- 29
- 1
2
votes
1 answer
Reading persisted data from Apple/Objective-C in C#/.NET
is there a C#/.NET library or otherwise existing code that can read persisted data from Apple's serialization API, namely NSKeyedArchiver, NSKeyedUnarchiver, NSCoder?
Context: A friend of mine created a cool app for some of the Apple devices. I have…

Marcel
- 15,039
- 20
- 92
- 150
2
votes
1 answer
How to update NSKeyedUnarchiver unarchiveObjectWithData to NSKeyedUnarchiver unarchivedObjectOfClass:[fromData:error:
My app currently uses this deprecated function:
id unarchivedObject=[NSKeyedUnarchiver unarchiveObjectWithData:codedData];
if([unarchivedObject isKindOfClass:[NSDictionary class]]){
// currently returns TRUE when reading existing user data.
}…

wayneh
- 4,393
- 9
- 35
- 70
2
votes
0 answers
How to initialize CMAttitude
Quick question.
I want the user to hold the iPhone upright and reset this orientation. I do this by using
currentAttitude.multiply(byInverseOf attitude: resetAttitude)
resetAttitude is being saved as soon as the user presses the "reset Button".
Now…

user9536730
- 21
- 1
2
votes
1 answer
Swift Save viewcontroller state using coder beyond app close
I am using Xcode 8 and swift 2.3
I want to save the entire view controller to file and restore state even after app closes.
I searched everywhere and found we need to use coder for that. but all just shows to save an object.
but here I need to save…

Sujay U N
- 4,974
- 11
- 52
- 88
2
votes
2 answers
Encode/Decoding Date with NSCoder in Swift 3?
I'm writing a planner app, based on Apple's FoodTracker tutorial, that stores several strings, a Date, and a UIImage per Assignment. I'm encountering problems encoding/decoding the Date. I don't know for sure which it is because the console outputs…

H. Martin
- 45
- 1
- 9
2
votes
0 answers
What is a strategy for saving completion handlers when using State Restoration on iOS?
I'm implementing State Restoration in my app to allow the app to return to right where it was after the app has been purged by the OS.
Encoding and decoding the necessary variables (such as text the user has typed in a text field) is fairly…

Doug Smith
- 29,668
- 57
- 204
- 388
2
votes
2 answers
required init?(coder aDecoder: NSCoder) not called
I wrote my own Button,Textfield, ..., classes. In the storyboard in "Custom Class" I set the class to the UIElement. This works very well.
Now I needed a toolbar that is added programatically. When I add the Toolbar in my ViewController everything…

kuzdu
- 7,124
- 1
- 51
- 69
2
votes
1 answer
Swift encodeObjectForKey - update value with nil
My first post in SE so please go gently on me.... :)
I'm new to swift and iOS dev but have been learning over the last few months.
I have an app that I use to hold dates and values via NSCoder and encodeObjectForKey. I pass NSDate values into this…

UKDevBloke
- 21
- 3
2
votes
0 answers
Adding an init() Method to SKScene
I'd like to add an init() to my class that inherits from SKScene instead of doing all my setup in the didMoveToView() method. The problem happens when I try to create a new instance of the scene nextScene = Level1(fileNamed: "Level1"). I get an…

claassenApps
- 1,137
- 7
- 14
2
votes
0 answers
How to reference existing objects during NSCoding state-restoration
I have a class that implements NSCoding and holds a reference to a UIView object...
class A: NSObject, NSCoding {
var view: UIView!
init(view: UIView) {
super.init()
commonInit(view)
}
required init?(coder aDecoder:…

sleep
- 4,855
- 5
- 34
- 51
2
votes
1 answer
Correctly init NSCoder in sub class when init NSCoder is convenience method in base class in Swift
Here's my code:
import Foundation
class Person: NSObject, NSCoding {
var name: String
init(name: String) {
self.name = name
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(name, forKey: "name")
}
required convenience…

petard
- 333
- 1
- 11
2
votes
0 answers
NSUserDefaults vs NSKeyedArchiver & NSCoder & Serialization
According to Apple's documentation, Archives convert data into architecture-independent byte streams. What is the difference between serializing data (like saving values to a property list) and archiving it?
Can archives be created with or without…

karan satia
- 307
- 4
- 16