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

How to save encoded object to a plist in Objective-C

Building for MacOS, In one of my classes, I am conforming to the NSCoding protocol to encode the properties of my objects and save them to a plist using this method: [NSKeyedArchiver archiveRootObject:employees…
Fady E
  • 346
  • 3
  • 16
1
vote
1 answer

Store and retrieve UIColor from Core Data using swift 5

The answers to the following questions are partially depreciated: Storing UIColor object in Core Data and Best way to save and retrieve UIColors to Core Data. 1) 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use…
DrWhat
  • 2,360
  • 5
  • 19
  • 33
1
vote
1 answer

Round-trip encoding and decoding with NSKeyedArchiver and NSKeyedUnarchiver

In the process of implementing init(coder:) for a custom NSView subclass, I came across some strange behavior with NSKeyedArchiver and NSKeyedUnarchiver that I still don't entirely understand. Consider this sample code: let label =…
Chris Frederick
  • 5,482
  • 3
  • 36
  • 44
1
vote
1 answer

unable to decode saved info in Swift

I am trying to save a very simple object using NSKeyedArchiver in swift, and I see that it is saving correctly, with values, but whenever it tries to decode the saved data it fails. I am new to swift and I have tried googling and os_log (ing)…
Neglected Sanity
  • 1,770
  • 6
  • 23
  • 46
1
vote
0 answers

NSKeyedArchiver sometimes makes a broken file

My iOS app saves NSCoding objects in Document directory. NSKeyedArchiver archives them. It is always O.K. but sometimes makes broken files. The broken files have the following two patterns. Lack of data I can convert them to ascii strings and…
1
vote
0 answers

I'm having problems un-archiving an NSMutableSet with circular references

I'm having problems unarchiving an NSMutableSet object in my iPhone (iOS 4.3) app. I have a subview of UIImageView that contains an ivar of type NSMutableSet. I have defined the NSMutableSet in the header (and synthesized it in the…
richardsun
  • 3,245
  • 1
  • 18
  • 22
1
vote
0 answers

How to save and load a gamescene in swift?

I'm trying to make a gamescene whith multiple layers of spritenodes persistent so that after you press start into the welcome screen, the last saved state of the gamescene gets loaded. I wrote encode/decode methods in the custom classes that i…
1
vote
1 answer

NSKeyedUnarchiver.unarchiveObjectWithFile crashes when loading classes created from a different target

I have a PLIST file that has been created using production version of the application and added as a resource to the project. The name of the target of production version is "little pony". In order to help with application testing there is another…
UrK
  • 2,191
  • 2
  • 26
  • 42
1
vote
1 answer

Writing data to a file with path using NSKeyedArchiver archivedData throws Unrecognized Selector for Swift 4.2

I am attempting to use the NSKeyedArchiver to write a Codable to disk. All the questions I could find on the subject using deprecated methods. I can't find any SO questions or tutorials using the Swift 4 syntax. I am getting the…
user-44651
  • 3,924
  • 6
  • 41
  • 87
1
vote
1 answer

NSKeyedArchiver how should i set path in iOS12

let person = Person() person.name = "zhangzhe" person.age = 25 print(self.home) do { try NSKeyedArchiver.archivedData(withRootObject: person, requiringSecureCoding: false) } catch { print(error) } I want to…
Zhe Zhang
  • 13
  • 3
1
vote
1 answer

How to restrict UIDocumentPickerViewController import to .archive files? (NSKeyedArchiver)

In an app that saves data as an archive (NSKeyedArchiver), I am allowing users to export the .archive file to have a backup. Users can then re-import those files to retrieve backed up data. Is there a way to restrict UIDocumentPickerViewController…
Kqtr
  • 5,824
  • 3
  • 25
  • 32
1
vote
2 answers

Using a singleton and archiving it

I have a class where I want to keep persistent settings throughout my app. This class is defined as: @interface Archive : NSCoder { NSString *fromAddress; NSString *toAddress; ... more ... } @property(nonatomic,retain) NSString…
Raisen
  • 4,385
  • 2
  • 25
  • 40
1
vote
1 answer

Use Codable to serialize custom class containing reference loop

I am trying to serialize a custom class containing a reference loop and got it working using NSCoding: import Foundation class Person: NSObject, NSCoding { let name: String weak var parent: Person? var child: Person? init(name:…
A. Vage
  • 35
  • 5
1
vote
1 answer

Crash while archiving data by NSKeyedArchiver

My app uses the following function to serialise a set of custom objects (only relevant code is shown): class func serializeShoppingLocations(buyLocations: Set) -> Data { #if os(iOS) …
Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
1
vote
0 answers

How do I convert an objective C interface to Xamarin for NSKeyedUnarchiver?

Short story: Old app is Objective C. New app (with same bundle ID, so it's an upgrade) is Xamarin on iOS. Old app stored data using NSKeyedArchiver. I need to get this data using the new Xamarin app. My preference is to create a new C# class to…
Adam Davis
  • 91,931
  • 60
  • 264
  • 330