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

NSKeyedArchiver not persisting data Swift 3

I have a an app in production I'm trying to convert from Swift 2.2 to Swift 3. I have tried the Swift 3 code in both XCode 8.1 and XCode 8.2. The following Swift 2 code works perfectly: func saveItemsToCache() { …
T. Steele
  • 325
  • 3
  • 14
1
vote
2 answers

Convert NSArray into NSData iOS objective-c

This is my code but i can't getting the data NSData *wrtData = [NSKeyedArchiver archivedDataWithRootObject:my_Array];
Inder
  • 29
  • 8
1
vote
1 answer

How do I archive this Swift dictionary from NSUserDefaults and send it via mail? Encoding seems garbled

I have the following code to turn NSUserDefaults into NSData and then send it with an instance of MFMailComposeViewController: let defaultsData =…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
1
vote
0 answers

Can't add data NSKeyedArchiver in NSUserDefauls Swift 3

I have a class Users. And I use NSKeyedArchiver add this in NSUserDefaults, but this does not work. This is my code: let encodedData = NSKeyedArchiver.archivedData(withRootObject: self.user) as Data self.prefs.setValue(encodedData, forKey:…
Humyl
  • 143
  • 2
  • 9
1
vote
1 answer

Passing Objects To WatchKit with NSKeyedArchiver

class Parent: NSObject, NSCoding { var name : String? var childs : [Child]? override init() {} func encode(with aCoder: NSCoder) { aCoder.encode(name, forKey: "name") aCoder.encode(childs, forKey: "childs") } …
szuniverse
  • 1,076
  • 4
  • 17
  • 32
1
vote
1 answer

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSKeyedArchiver unarchiveObjectWithFile:]

I'm following the FoodTracker demo at developer apple. I'm on the last section: Persist data. I'm running Xcode 8, and following the demo building on Swift 3. If I download the code and convert to Swift 2.3, it doesn't work. If I convert to Swift…
PixelStack
  • 75
  • 1
  • 7
1
vote
1 answer

How to Save complex Arrayobjects to device using NSKeyedArchiver swift

I want to save an array of any class (e.g let array = SymptomsModel) type into device using NSKeyedArchiver in swift . I Know how to save an array if SymptomsModel class contains all variables with primitive data types , but don't know how to save…
Preeti Rani
  • 685
  • 7
  • 17
1
vote
1 answer

about NSKeyedArchiver archiveRootObject:toFile:

I have a very simple question, I just can't find a proper answer. That's [NSKeyedArchiver archiveRootObject:value toFile:filePath]; according to apple documentation here, the above function: Archives an object graph rooted at a given object by…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
1
vote
1 answer

encodeWithCoder Not getting called

I have an object (testSession) that complies to NSCoder and when I use: [NSKeyedArchiver archiveRootObject:testSession toFile:filename]; It has: @interface Session : NSObject { and has encodeWithCoder: and initWithCoder: functions.…
Dane Man
  • 21
  • 2
1
vote
2 answers

Location for archiving on iPhone

I'm looking to archive some nested NSDictionary objects to be able to use the data in them at next start. To do so I was going to use [NSKeyedArchiver archiveRootObject: toFile: ] but was not sure where to put the file. In the archiving docs, the…
mmdeas
  • 183
  • 3
  • 10
1
vote
2 answers

Archiving and unarchiving Arrays in the DocumentDirectory in Swift

I am trying to save a simple array of objects in the persistent memory by executing the following code: let fileManager=NSFileManager() let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) if…
1
vote
2 answers

NSCoding : How to create required init in inherited classes

I have the same question as vince (NSCoding required initializer in inherited classes in Swift) I've a class 'Source' and a subclass 'RSSSource'. Theses classes conforms to NSObject and NSCoding which I want to be able to persist with…
Thibault B.
  • 108
  • 10
1
vote
1 answer

Saving data in non-document based application

I have an app similar structured to the new Notes app. A sidebar contains information about different files (date, title, excerpt) and the detail view shows the whole content. To store data in my app, I use NSKeyedArchiver. Each file is stored…
mangerlahn
  • 4,746
  • 2
  • 26
  • 50
1
vote
0 answers

NSKeyedArchiver archivedDataWithRootObject: Doesn't update object?

I've followed some other threads and successfully did the save/load custom objects to NSUserDefaults using NSCoding protocol. But, strange thing is: I can't update the object. Here's some block of codes (Note: XUtil objectForKey: and…
Eddie
  • 1,903
  • 2
  • 21
  • 46
1
vote
1 answer

iOS SWIFT - File Archive - Argument Type "[String?]" : does not conform to expected type'AnyObject'

I am trying to write into an Archive and getting this error . My tech stack is : XCode 7.1 Beta and SWIFT .Appreciate if any of you could share the exact code to fix this issue. Thanks in advance. Argument Type "[String?]" : does not conform to…