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
2
votes
1 answer

Storing custom objects as NSDictionary vs NSData

I was going through some tutorials regarding storing custom objects in NSUserDefaults. I can't figure out which is the better approach and/or benefits regarding storing your model after converting it back to NSDictionary and storing the dictionary…
Rikh
  • 4,078
  • 3
  • 15
  • 35
2
votes
1 answer

NSKeyedArchiver archivedDataWithRootObject return nil when passed an array of image model

I am trying to save an array containing models which consist of an image and a string using [NSKeyedArchiver archivedDataWithRootObject:dataArray]; but this method returns nil after 2-3 times of calling this method . This only happens when the…
2
votes
0 answers

NSUserDefaults vs NSKeyedArchiver & NSCoder & Serialization

According to Apple's documentation, Archives convert data into architecture-independent byte streams. What is the difference between serializing data (like saving values to a property list) and archiving it? Can archives be created with or without…
karan satia
  • 307
  • 4
  • 16
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
1 answer

NSKeyedArchiver & NSKeyedUnarchiver depending on bundli-ID

I have an App with 2 Targets: APP_TARGET1 & APP_TARGET2 I am Serializing an Object in my APP_TARGET1 and store it (sqlite, file) let data : NSData = NSKeyedArchiver.archivedDataWithRootObject(maptheme); I am reading back the blob/file with…
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
2
votes
2 answers

How can I prevent TableView cells from duplicating? Swift

So I am building a notes app and have tried everything but can not figure this issue out. I have 3 UIViewController's. When you click a button on the first UIViewController, it shoots you over to the third one which consist of a UITextView,…
JakeC
  • 231
  • 1
  • 2
  • 9
2
votes
1 answer

What character encoding or file format does NSKeyedArchiver use?

I am currently investigating a crash during unarchiving of a file supposedly stored through NSKeyedArchiver. The crash log contains the first 8 byte quartets of the file (I only included the first 2 below). Fatal Exception:…
hennes
  • 9,147
  • 4
  • 43
  • 63
2
votes
0 answers

Can not archive NSDictionary with NSKeyedArchiver - method does not get called

I've recently gotten into a problem where for some reason I simply can not get Xcode to call the archiveRootObject:toFile: method. I think it has something to do with what the NSMutableDictionary contains, because I've been able to replace the…
2
votes
0 answers

How can an NSIndexSet be a root object?

Here is a typical code snippet when reordering a table with drag and drop. - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard { NSData *data = [NSKeyedArchiver…
Bob Ueland
  • 1,804
  • 1
  • 15
  • 24
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
2 answers

NSKeyedArchiver: key returning nil - Swift

I'm having some issues here. I'm trying to store some information with NSKeyedArchiver, but when I run the app, I get: fatal error: unexpectedly found nil while unwrapping an Optional value. Apple docs says: "If you invoke one of the decode...…
Nicholas Piccoli
  • 188
  • 1
  • 2
  • 14
2
votes
1 answer

What happens with unarchived objects?

After I've unarchived an object with NSKeyedUnarchiver, I am able to use it like usual, but I am unable to re-archive it. When I try, it crashes. [NSKeyedArchiver archiveRootObject:unarchivedObject toFile:fileName]; I tried looking in the developer…
Dane Man
  • 71
  • 1
  • 6
2
votes
2 answers

NSInvalidUnarchiveOperationException raised only in iOS extension, not main app

I have archived an Array of my NSCoding-conforming class "Assignment" to a file in a shared (App Groups) container: class private func updateSharedFiles() { let path =…
PopKernel
  • 4,110
  • 5
  • 29
  • 51
2
votes
1 answer

How can I import a model object file into my watch extension if it has a lot of dependencies

I am working on building a companion app to an existing iOS app that is quite large and has pieces that are somewhat archaic. There is a list in the iOS app that has items that are of type ClassA lets say. Persistence is handled by archiving these…
Lizza
  • 2,769
  • 5
  • 39
  • 72
2
votes
1 answer

NSKeyedUnarchiver - Bad access

I was trying to archive an object into a plist file and load it later to fill a tableView. It seems that the file gets archived correctly but I get a bad access when trying to get the value out of the file. Am I doing something wrong? This is where…
Chris
  • 3,581
  • 8
  • 30
  • 51