Questions tagged [nskeyedunarchiver]

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyedArchiver class.

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyedArchiver class.

A keyed archive is encoded as a hierarchy of objects. Each object in the hierarchy serves as a namespace into which other objects are encoded. The objects available for decoding are restricted to those that were encoded within the immediate scope of a particular object. Objects encoded elsewhere in the hierarchy, whether higher than, lower than, or parallel to this particular object, are not accessible. In this way, the keys used by a particular object to encode its instance variables need to be unique only within the scope of that object.

Click Here for class reference.

191 questions
41
votes
5 answers

How can I decode an object when original class is not available?

I have an iOS 7 application that saves a custom object to app's iCloud Docs folder as a file. For this, I make use of NSCoding protocol. @interface Person : NSObject @property (copy, nonatomic) NSString *name @property (copy,…
Aнгел
  • 1,153
  • 2
  • 14
  • 24
34
votes
4 answers

Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

NSKeyedUnarchiver.decodeObject will cause a crash / SIGABRT if the original class is unknown. The only solution I have seen to catching this issue dates from Swift's early history and required using Objective C (also pre-dated Swift 2's…
simons
  • 2,220
  • 2
  • 16
  • 20
22
votes
6 answers

Unarchive Array with NSKeyedUnarchiver unarchivedObject(ofClass:from:)

Since upgrading to Swift 4.2 I've found that many of the NSKeyedUnarchiver and NSKeyedArchiver methods have been deprecated and we must now use the type method static func unarchivedObject(ofClass: DecodedObjectType.Type, from:…
Geoff H
  • 2,688
  • 1
  • 25
  • 45
21
votes
2 answers

NSKeyedUnarchiver - try/catch needed?

As I understand, the use of @try/@catch blocks is discouraged, because exceptions should only be thrown at unrecoverable, catastrophic errors (refer to this discussion with a nice answer by @bbum: Exception Handeling in iOS). So I looked through my…
Mario
  • 4,462
  • 1
  • 17
  • 30
13
votes
4 answers

swift: nscoding decodeObject with nil all the time

I got the following codes on writing an object named Packet and send to the other side through Multipeer connectivity. However, I got the following error whenever it try to decode the encoded object. class Packet : NSObject, NSCoding { var…
user6539552
  • 1,179
  • 2
  • 12
  • 35
12
votes
0 answers

Failed to initialise color list unarchiver

Whenever I open an emacs file at the terminal, the following type of message occurs: mm-Pro:~ mm$ emacs experiment.hs 2019-02-21 15:56:19.243 Emacs[2937:261832] Failed to initialize color list unarchiver: Error Domain=NSCocoaErrorDomain…
user65526
  • 615
  • 4
  • 18
12
votes
3 answers

Cannot decode object of class Employee for key (NS.object.0); the class may be defined in source code or a library that is not linked

Im trying to pass an array of 'Employee' objects iPhone to Apple Watch by serializing the array : NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:employees]; and unserializing it as on the Watch side: NSMutableArray *employees =…
10
votes
2 answers

How to NSKeyedUnarchiver.unarchiveObject

I have a working code that works but deprecated: This part is fine: let archived = try? NSKeyedArchiver.archivedData(withRootObject: [defaultRecord] as NSArray, requiringSecureCoding: false) This is Deprecated: let records =…
Spring
  • 8,976
  • 26
  • 96
  • 175
10
votes
3 answers

How to use the delegates with NSKeyedUnarchiver?

I am using NSKeyedUnarchiver to unarchive an object and would like to use the delegates (NSKeyedUnarchiverDelegate), but my delegates are not called. Archiving and Unarchiving is working fine, but the Delegates (unarchiver & unarchiverDidFinish) are…
mcfly soft
  • 10,143
  • 21
  • 80
  • 162
7
votes
4 answers

Unarchiving encoded data returning nil and incorrect format

I have added category methods to NSUserDefaults to store and retrieve encoded objects (in this case, an NSArray). I am having a problem retrieving the encoded data. Here is my code: - (void)encodeObject:(id)object forKey:(NSString *)key { …
mashers
  • 939
  • 6
  • 20
7
votes
1 answer

NSKeyedUnarchiver not working with Swift 3

I have the following code that I use to unarchive a file in my Mac application: func tryOpen(_ filePath: String) throws -> NSArray { if #available(OSX 10.11, *) { do { if let data = try? Data(contentsOf: URL(fileURLWithPath:…
Matt
  • 2,180
  • 5
  • 29
  • 49
7
votes
6 answers

NSKeyedUnarchiver error after renaming Xcode project

I just renamed my Xcode project and when I ran it I got this error: 2015-11-14 05:32:42.337 Buck Tracker[3537:1456100] * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver…
hklel
  • 1,524
  • 19
  • 42
7
votes
1 answer

Added a custom framework, now Swift can't unarchive data

I have a pretty trivial Swift app that has a model class named DemoNote. An array of DemoNote instances is read/written via keyed archiving. This worked fine while DemoNote was included in the app. But then I moved DemoNote.swift to a new custom…
Tom Harrington
  • 62,792
  • 9
  • 129
  • 149
7
votes
1 answer

NSKeyedArchiver unarchiveObjectWithFile crashes with EXC_BAD_INSTRUCTION

I have the following code, used to get the path of an object that has been archived let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let path = paths[0] as…
JuJoDi
  • 13,081
  • 22
  • 75
  • 121
6
votes
1 answer

Catching NSKeyedUnarchiver exception

In Swift, NSKeyedUnarchiver.unarchiveObjectWithData(data) will throw an exception if data can't be unarchived. There are some situations where we have no guarantee if that the data is not corrupted, such as when reading from a file. I am not aware…
JP Hribovsek
  • 6,587
  • 2
  • 19
  • 26
1
2 3
12 13