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
6
votes
3 answers

NSKeyedArchiver - Unrecognized selector sent to instance error

I'm facing unrecognized selector sent to instance error while using NSKeyedArchiver.archivedData. I was trying to store parse the JSON output to the custom class object and store it in NSUserDefaults on successful login. I wanted to use these…
ASN
  • 1,655
  • 4
  • 24
  • 52
6
votes
2 answers

NSKeyedArchiver archivedDataWithRootObject:

Is the parameter for NSKeyedArchiver archivedDataWithRootObject: supposed to be the array I am trying to save, or the array converted into NSData?
node ninja
  • 31,796
  • 59
  • 166
  • 254
6
votes
1 answer

NSKeyedArchiver archiveRootObject always returns NO

I'm new to objective C and writing some simple programs to familiarize myself. Trying to save / read information with NSKeyedArchiver but every time I do it fails to create the .plist file. I've looked around and haven't been able to find an answer.…
E.T.
  • 137
  • 2
  • 7
6
votes
1 answer

NSKeyedUnarchiver fails to decode a custom object in swift

I'm trying a basic implementation of the NSCoding protocol in swift, but it seems I can't success to unarchive an object after it has been correctly archived. Here's my attempt import Cocoa class User: NSObject, NSCoding { var name: String …
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
6
votes
4 answers

NSKeyedArchiver and NSKeyedUnarchiver with NSMutableArray

I'm hoping this isn't something to do with the fact that I'm using a Mutable array here, but this one is baffling me so it wouldn't surprise me if that were the case. BACKGROUND: I have made a small database which is essentially an NSMutableArray…
5
votes
3 answers

NSArchiver vs NSKeyedArchiver performance

Why is NSKeyedArchiver performance so poor? The size doubles vs using NSArchiver. I am encoding an NSMutableArray of objects with the following line BOOL result = [NSArchiver archiveRootObject:self.appDataObject.materias toFile:archivePath]; the…
Ben Quan
  • 773
  • 11
  • 25
5
votes
1 answer

NSKeyedArchiver returning nil Swift 4.2

let lessons = Lessons(definition: "testo", photo: url) SaveUtil.saveLessons(lessons: lessons!) let x = SaveUtil.loadLessons() So everything compiles and runs but x is nil....I'm trying to make this ios12/swift 4.2 compliant but no idea what is…
hunterp
  • 15,716
  • 18
  • 63
  • 115
5
votes
3 answers

Class conforming to Codable protocol fails with encodeWithCoder: unrecognized selector sent to instance

I know that there are several questions similar to this, that tend to all revolve around the class not conforming to the protocol properly, but that should not be the immediate issue here. The following is a condensed version of the code that is…
CodeBender
  • 35,668
  • 12
  • 125
  • 132
5
votes
2 answers

NSKeyedArchiver.archivedData does not work in Swift 3 iOS

When try to encode my custom object in iOS swift get this error from Xcode 8.3 unrecognized selector sent to instance 0x60800166fe80 *** -[NSKeyedArchiver dealloc]: warning: NSKeyedArchiver deallocated without having had -finishEncoding called on…
reza_khalafi
  • 6,230
  • 7
  • 56
  • 82
5
votes
3 answers

NSCoder crash on decodeBool forKey (Xcode 8, Swift 3)

I have this simple class import UIKit class SimpleModel: NSObject, NSCoding { var name : String! var done : Bool! init(name:String) { self.name = name self.done = false } internal required init?(coder…
Enlil
  • 1,027
  • 14
  • 28
5
votes
1 answer

Pass nil to archivedDataWithRootObject return weird NSData

Somewhere in my code NSData *data = [NSKeyedArchiver archivedDataWithRootObject:someArray]; I expect data to be nil if someArray is nil, but it return some data I don't understand. I print it out as below <62706c69 73743030 d4010203 0405080a…
Gary Lyn
  • 1,088
  • 9
  • 11
4
votes
2 answers

MKPolyline -> NSKeyedArchiver -> NSData SIGABRT

In my app I am trying to store an array of MKPolylines into NSUserDefaults. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:overlays]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"]; Gives: [MKPolyline…
eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
4
votes
1 answer

streaming images over bonjour between two iOS device

My goal is to stream images captured by AVCpatureInput from one iOS device to another via bonjour. Here is my current method: 1) Capture frame from video input - (void)captureOutput:(AVCaptureOutput *)captureOutput…
phmagic
  • 691
  • 8
  • 10
4
votes
2 answers

How to parse the contents of a foreign file created with NSKeyedArchiver

I need to be able to compare two versions of a plist file created with NSKeyedArchiver. In particular, it's the "elements" file created in Xcode for a .xcdatamodeld file. Since I have not created this file myself I can not recreate its object model.…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
4
votes
1 answer

NSKeyedArchiver encode only part of an array

I have a list of objects that can sometimes change, and I want to keep a persistent cache on the device whenever the app is closed or move to the background. Most of the objects in the list will not change, so i was wondering what is the best way to…
Adam
  • 81
  • 1
  • 2
1 2
3
37 38