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

How to load an Objective C Singleton using NSCoding?

I am writing a basic game, I am using a GameStateManager which is a singleton and handles all state management, such as saves, loads, delete methods. I have a separate singelton which handles all the Game stuff. The game object is inside the game…
zardon
  • 2,910
  • 6
  • 37
  • 58
2
votes
1 answer

Unarchiving UIImageView with subviews

I'm going a bit crazy trying to archive and unarchive a UIImageView which has number of subviews which are custom views derived from UIImageView. Here's what I've done: Add a category to the project to allow for the fact that UIImage does not…
beev
  • 1,197
  • 2
  • 16
  • 33
2
votes
1 answer

Initializing a static singleton object with NSCoder

I'm working on an iPhone app and facing some troubles with my shared singleton class. I'm using a shared singleton to store two variables int gameRuns and int totalScore 'gamRuns' just increments every time the user loads the app, and 'totalScore'…
2
votes
1 answer

NSCoding NSKeyedUnarchiver unarchiveObjectWithFile: returning null

I am trying to save some values from my app using NSCoding. I'm able to save the value but not able to retrieve it. Here's where I am declaring the protocol: @interface AddReminderEventViewController : UIViewController
Jazzmine
  • 1,837
  • 8
  • 36
  • 54
2
votes
3 answers

Saving [UIColor colorWithPatternImage:image] UIColor to Core Data using NSKeyedArchiver

I'm unable to create an NSData object from a UIColor (with a pattern) created with the factory method [UIColor colorWithPatternImage:image] works fine for standard UIColor objects. Wondering if there is another way to save a UIColor with a pattern…
Nate Potter
  • 3,222
  • 2
  • 22
  • 24
2
votes
2 answers

Encode/decode NSCoder data in C++

I'd like to send serialized objects between a C++ application (running on a linux machine) and an iPhone application. Is this possible? Is there a way to encode/decode data using the NSCoding protocol on the C++ side? Has someone reverse engineered…
jonas
  • 143
  • 1
  • 9
2
votes
1 answer

How to read file as String in Flutter that has been written to filesystem using NSKeyedArchiver in iOS?

After updating iOS native app with an app written on Flutter I want to read a file from filesystem on iOS device using Dart. The file I want to read has been previously written to filesystem using this ObjectiveC code: -…
Sergio
  • 27,326
  • 8
  • 128
  • 149
2
votes
5 answers

Singleton does not persist from app delegate into another view controller

Following this link: How do I archive two objects using NSKeyedArchiever? I am able to archieve an array and a singleton object. I can archieve and correctly unarchieve it at didFinishLaunchingWithOptions. However, my singleton object does not…
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
2
votes
1 answer

iOS: Appending to an archive

Can anyone recommend a memory-efficient way to append data to an archive using NSKeyArchiver? I have an array which collects objects and makes them available to the app as an in-memory cache. In order to avoid eating more and more memory, I'd like…
100grams
  • 3,502
  • 3
  • 30
  • 27
2
votes
1 answer

Limitations of NSMutableData for NSKeyedUnarchiver

I have read on another post (Archiving / Unarchiving results in initForReadingWithData incomprehensible archive) that you can't store more than 250kBytes on a NSMutableArray. Unfortunately, in order to recover such data with NSKeyedUnarchiver, you…
Plot
  • 898
  • 2
  • 15
  • 26
2
votes
1 answer

Extracting Data from NSKeyedArchiver in Non-ARC Code

In my non-ARC iOS project, I have a method that returns archived data: - (NSData*) archivedData { NSMutableData* data = [[NSMutableData alloc] init]; NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; …
THLO
  • 133
  • 1
  • 1
  • 4
2
votes
1 answer

NSKeyedUnarchiver.unarchiveTopLevelObjectWithData return nil

I want to save an array of objects into UserDefaults and load it back. When trying to unarchive the data it always returns nil.. any idea? This is my object: class DbInsideLevel: NSObject, NSSecureCoding { static var supportsSecureCoding:…
ytpm
  • 4,962
  • 6
  • 56
  • 113
2
votes
0 answers

NSKeyedUnarchiver unarchivedObjectOfClass implementation gives error

I am updating an old Objective C app that uses 'NSKeyedUnarchiver unarchiveObjectWithData' which is now deprecated. The app archives an array consisting of custom objects that contain (among other things) another array of a different custom object.…
Bob
  • 559
  • 1
  • 5
  • 18
2
votes
0 answers

NSKeyedArchiver Unable to Save or Load Data When Trying to Persist Data in Swift

I've been working on a basic iOS Food Tracker using Apple's Developer tutorial. When I got to the "Persisting Data" step, I realized that the functions used have been deprecated, so I've searched online to find the updated/working version. I've…
JennyW23
  • 21
  • 2
2
votes
1 answer

NSKeyedArchiver deprecated method problem

Just a little background info. I lost my ability to speak a few years ago and learned how to code specifically to make a good text to speech app for myself. Amazingly a lot of others find it useful. Apple reports around 15,000 sessions per week. It…
d.altman
  • 355
  • 4
  • 15