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.

203 questions
2
votes
1 answer

NSKeyedUnarchiver decodeObjectForKey: cannot decode object of class for key (NS.objects)

I looked through whole SO but still no answer. My app reports this problem: Fatal Exception: NSInvalidUnarchiveOperationException *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (App_Title.Products) for key…
S. Gissel
  • 1,788
  • 2
  • 15
  • 32
2
votes
1 answer

NSKeyedArchiver and sharing a custom class between targets

My app uses a custom class as its data model: class Drug: NSObject, NSCoding { // Properties, methods etc... } I have just created a Today extension and need to access the user’s data from it, so I use NSCoding to persist my data in both the…
Chris
  • 4,009
  • 3
  • 21
  • 52
2
votes
1 answer

Swift NSCoding - How to read an encoded array

I'm using Swift playground to write a parent-child relationship using NSCoding. The relationship can be described as: One Author can write many Books However, it causes an error when I try to save the collection of books; Playground execution…
zardon
  • 1,601
  • 4
  • 23
  • 46
2
votes
1 answer

Does NSKeyedArchiver overwrite the previous archive value?

I am using the following to do IOS App data backup NSKeyedArchiver.archiveRootObject() NSKeyedUnarchiver.unarchiveObjectWithFile() Based on the Apple documentation here - iOS Developer Library - iOS Apps (Swift) - Persist Data I was curious…
J-Dizzle
  • 4,861
  • 4
  • 40
  • 50
2
votes
0 answers

Share custom data with today extension by NSUserDefaults

this is my first post, so please be kind and constructive with me. Im trying to share an array of custom objects with my Today Extension via NSuserDefauls. I know that I can't put custom objects in NSUserdefaults so i coded them by NSKeyedArchiver -…
2
votes
3 answers

iOS: count of objects (0) differs from count of keys

I have faced an issue which I have no idea what went wrong. I have a method for saving info into NSUserDefaults and then another method for retrieving it. But when I retrieve it the error message came up: *** Terminating app due to uncaught…
2
votes
1 answer

[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0xffffffff, 0xffffffd8, 0xffffffff, 0xffffffe0, 0x0, 0x10, 0x4a, 0x46)

In my app i Archive myObject to NSData and then Unarchive NSData to get myObject. Crash trace 0 CoreFoundation 0x2fe9ef46 __exceptionPreprocess + 126 1 libobjc.A.dylib 0x3a1b36aa objc_exception_throw + 34 2 …
2
votes
2 answers

self referencing NSMutableDictionary

Say I have this: NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[@1] = @2; dict[@3] = dict; I archive dict by calling: NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict]; then I unarchive later: NSMutableDictionary…
1
vote
2 answers

How to replace NSKeyedUnarchiver.unarchiveTopLevelObjectWithData with unarchivedObject when data is a Dictionary

iOS 16.4 deprecates unarchiveTopLevelObjectWithData(_:) and should be replaced with unarchivedObject(ofClass:from:). When you archived a Swift Dictionary like [String: Any], how do you use the newer API to unarchive…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
1
vote
1 answer

Decoding NSArchiver with NSKeyedUnarchiver

I have some old archives that are basically stored preferences created with NSArchiver. I want to be able to decode them with NSKeyedUnarchiver since the NSArchiver/NSUnarchiver are deprecated in favor of their keyed counterparts. Is there any way…
Trygve
  • 1,317
  • 10
  • 27
1
vote
1 answer

Unarchiving data with new NSKeyedUnarchiver APIs while failed to satisfied unarchivedObjectOfClass it required

Firstly, I wanted to thank every of you have read the message and giving me feedback in any form. Here it's what I'm trying to do. To replace deprecated API [NSKeyedUnarchiver unarchiveObjectWithData:myProfileData]; in objective-c to iOS 12 new API…
1
vote
1 answer

Swift: nskeyedunarchiver fails and terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count]

NSKeyedUnarchiver.UnarchivedArrayOfObjects() terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count] track conforms to NSManagedObject However decodedTrackLocation is declared @Published public var decodedTrackLocation:…
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

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…