Questions tagged [nskeyedarchiver]

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.

A keyed archive differs from a non-keyed archive in that all the objects and values encoded into the archive are given names, or keys. When decoding a non-keyed archive, values have to be decoded in the same order in which they were encoded. When decoding a keyed archive, because values are requested by name, values can be decoded out of sequence or not at all. Keyed archives, therefore, provide better support for forward and backward compatibility.

Click Here for class reference

570 questions
1
vote
1 answer

NSKeyedArchiver will not archive simple dictionary with enum as value

I am trying to use NSKeyedArchiver to "archive" a simple dictionary. The key is of type String and the value is an enum. The following example illustrates what I am trying to do: import Foundation enum Friend: String, Codable { case Ben,…
Jens
  • 20,533
  • 11
  • 60
  • 86
1
vote
1 answer

UserDefaults.standard.set(Image Array) takes more than 10 second

UserDefaults.standard.set(NSKeyedArchiver.archivedData(withRootObject: sortedImage), forKey: "StoredData.homePageImages") takes more than 10 seconds. Does this make sense? Any suggestions? func printTime() { let date = Date() let calendar =…
Pak Ho Cheung
  • 1,382
  • 6
  • 22
  • 52
1
vote
1 answer

Does NSCoding / NSKeyedArchiving data persist through a major iOS update?

Will the data persist through a major update, such as from iOS 10 to iOS 11? Any reason it might not?
trishcode
  • 3,299
  • 1
  • 18
  • 25
1
vote
1 answer

Encoding and decoding custom subclass object getting fatal error: unexpectedly found nil while unwrapping an Optional value

I have 2 objects, 1 which is a subclass of the other. When I try to unarchive the subobject I get fatal error: unexpectedly found nil while unwrapping an Optional value even when I manually test archiving and unarchiving the object. Specifically I…
14wml
  • 4,048
  • 11
  • 49
  • 97
1
vote
3 answers

NSKeyedUnarchiver crashes swift 3 on the second run

I am trying to save custom object to UserDefaults and I'm using this as a source code. It crashes immediately on the get part. This is my code: class Settings { static let defaults:UserDefaults = UserDefaults.standard ///VIP object: class VIP:…
Async-
  • 3,140
  • 4
  • 27
  • 49
1
vote
0 answers

NSKeyedUnarchiver returns nil - Could not cast value of type 'MyProj.Meal' (0x105373f68) to 'MyProj.Meal' (0x11f5ee928)

I'm trying to get the hang of archiving objects. I'm following Apple's example project for persistence here: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/PersistData.html Basically there's a Meal…
rclark
  • 301
  • 3
  • 13
1
vote
1 answer

Swift: Error in NSKeyedArchiver

Swift 3 iOS 10, Trying to save array with custom objects in NSKeyedArchiver, basically trying to save the table view after the user uses the buttons to switch between sections. I've tried several post to solve the issue but no luck, now I'm trying…
WokerHead
  • 947
  • 2
  • 15
  • 46
1
vote
0 answers

Swift 3: NSCoder Crash (encodeWithCoder: unrecognized selector sent to instance)

The error that is crashing my app when I click the save button -[BlogApp.Blog encodeWithCoder:]: unrecognized selector sent to instance 0x7fbe31d33800 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:…
WokerHead
  • 947
  • 2
  • 15
  • 46
1
vote
2 answers

Can you save an array of ViewControllers locally (NSKeyedArchiver) in swift?

I'm currently hired to create the data handling part of a local document iOS application. I wasn't involved in creating the UserInterface and so I'm in need of help. The problem: The person(s) that created the user interface implemented all the data…
1
vote
2 answers

Store Custom Objects in NSUserDefaults

I am trying to store a custom objects as follows, but I am getting an error. // store data NSMutableArray *archiveArray = [NSMutableArray arrayWithCapacity:pOrderElements.count]; for (id orderObject in pOrderElements) { NSData…
casillas
  • 16,351
  • 19
  • 115
  • 215
1
vote
1 answer

How to take screenshot of a uiview and drag in swift?

i got the code but its not working, let me know if im did anything wrong. In the code i have a imageview which i created programmatically and adding the image into a uiview.Right now im unable to load the image in the "draggingView". func…
Joe
  • 859
  • 2
  • 10
  • 27
1
vote
1 answer

Custom object inheriting NSMutableDictionary and serialized with NSKeyedArchiver can't be deserialized

Class is not unarchived properly. See code example below. @interface A : NSMutableDictionary @end @implementation A - (void)encodeWithCoder:(NSCoder *)aCoder { } - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super…
1
vote
0 answers

TableView Empty from NSUserDefaults

In my Swift iOS app, I have a table view which is supposed to show JSON objects from a mysql server, like a blog reader app. BUT now the table view is showing up empty because I tried implementing NSUserDefaults to save when the user clicks a button…
WokerHead
  • 947
  • 2
  • 15
  • 46
1
vote
1 answer

NSKeyUnarchiver causing Crash

Swift 3, I'm using NSUserDefaults in my iOS app to save and load the indexPath and which section the row that the action took place in. As I have a button in each row in my tableview. To be loaded again whenever it reloads the table, in…
WokerHead
  • 947
  • 2
  • 15
  • 46
1
vote
1 answer

Spritekit Scene Archiving

The SpriteKit programming guide contains this useful little tidbit: Store a game level as an archive of a scene node. This archive includes the scene, all of its descendants in the node tree, and all of their connected physics bodies, joints, and…
Zek
  • 155
  • 7