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
0 answers

How do I unarchive an NSArray using NSKeyedUnarchiver Objective C

Id welcome any help unarchiving an NSArray of UIBezierPaths from NSData. I want to use the NSArray container to hold some UIBezierPaths which I can persist to Core Data as an NSData property in my entity (rather than persist them individually, which…
MiltsInit
  • 153
  • 7
1
vote
0 answers

iOS 13 Fonts for NSAttributedString when NSKeyedUnarchiver.unarchivedObject has CoreText issues

I use NSKeyedArchiver.archivedData to transfer my NSAttributedString to Data and saved it to Realm or UserDefaults. Here is the extension that I implemented. It works pretty well before iOS 13 extension NSAttributedString { func toData() ->…
1
vote
1 answer

Cannot use NSKeyedArchiver to save my model

I am getting model from Api and it looks like this: class Device : NSObject, Codable, NSCoding{ var deviceId : Int? var driver : String? var address : String? var type : DeviceTypes? // Enum type func encode(with coder: NSCoder)…
1
vote
1 answer

iOS 13 NSKeyedUnarchiver EXC_BAD_ACCESS

I've spent the better part of a day and half now trying to debug this issue I'm seeing when trying to unarchive a Data blob stored locally (this issue also appears when retrieving it via iCloud, but since they run through the same codepath, I assume…
1
vote
1 answer

Synchronized NSKeyedArchiver or NSUserDefaults

I have a singleton delayed-transaction manager class, which is responsible for enqueueing and dequeueing iphone-to-app-server transactions that cannot complete due to a variety of factors (network reachability, proximity, etc). When…
Rayfleck
  • 12,116
  • 8
  • 48
  • 74
1
vote
2 answers

Trying to save custom object in UserDefaults using NSKeyedArchiver

I want to save my custom class object in userdefault. I'm trying to save it like this: class func setModel(model: T, key: String) { let encodedData: Data = NSKeyedArchiver.archivedData(withRootObject: model) …
1
vote
1 answer

Facing issue while unarchivedObject data

I have created a generic function for NSKeyedArchiver and NSKeyedUnarchiver. I am able to archive the array data but while doing unarchive facing an issue. Below is my code: NSKeyedArchiver code: func cacheData(data: T) { do { …
Kirti Nikam
  • 2,166
  • 2
  • 22
  • 43
1
vote
1 answer

NSKeyedArchiver can not archive an object

I have a JSON file I am reading from disk This is the structure of the file: [ { "name": "3X", "priority": 33 }, { "name": "4X", "priority": 32 } ] I am decoding it to a class called Test class TestClass: NSObject, Codable { …
Eli Braginskiy
  • 2,867
  • 5
  • 31
  • 46
1
vote
1 answer

Invalid Summary on NSMutableArray

I would need some expert advice on how to solve this problem. I am doing some crude testing for a new app for the iPad. I create a NSMutableArray (ballPath) in the viewDidLoad of my view controller (it is declared in my .h file) by loading a plist…
Structurer
  • 694
  • 1
  • 10
  • 23
1
vote
1 answer

NSKeyedArchiver not saving all properties of an object

I am having an issue where I am saving, among other things, an array of "nodes" (header below) that posses a color and a tag property. When it saves as in - (void)saveDataToDiskWithPath:(NSURL*)path, the log shows that these properties exist. When…
diatrevolo
  • 2,782
  • 26
  • 45
1
vote
1 answer

iOS - unarchive NSSecureCoding Object that has a property of type Date

@objc(EventNotificationInfo) class EventNotificationInfo: NSObject, NSSecureCoding { public var name: String public var startTime: Date public var hexColor: String init(name: String, startTime: Date,…
mahan
  • 12,366
  • 5
  • 48
  • 83
1
vote
1 answer

-[__NSCFArray bytes]: unrecognized selector sent to instance

I have saved the array of my products in the user default as below: NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:[NSKeyedArchiver archivedDataWithRootObject:plans] forKey:@"plans"]; …
ios23
  • 353
  • 2
  • 8
1
vote
1 answer

Save A Non-Codable Swift Dictionary Using NSKeyedArchiver

I’m looking to save a swift struct that includes a dictionary to data using NSKeyedArchiver. The reason I’m using NSKeyedArchiver is because the dictionary has a non-codable variable associated with it. I'm following this guide from Paul Hudson. The…
Richard Witherspoon
  • 4,082
  • 3
  • 17
  • 33
1
vote
1 answer

Remove data from NSKeyedArchvier

I am storing data with NSKeyedArchiver. When a user logs out of my app, I would like to clear all the data that I have stored. How can I go about doing that? It doesn't appear that [NSKeyedUnarchiver unarchiveObjectWithFile:] removes the…
lavoy
  • 1,876
  • 3
  • 21
  • 36
1
vote
2 answers

Preferred file extension

I am saving with NSKeyedArchiver. What should the file extension of my file name be?
Blane Townsend
  • 2,888
  • 5
  • 41
  • 55