nscoding

Why NSUserDefaults failed to save NSMutableDictionary in iPhone SDK?

I'd like to save an NSMutableDictionary object in NSUserDefaults. The key type in NSMutableDictionary is NSString, the value type is NSArray, which contains a list of object which implements NSCoding. Per document, NSString and NSArray both are conform to NSCoding. I am getting error : -[NSUserDefaults setObject:forKey:]: Attempt to i...

UIWebView incl. content encoding/decoding

My aim: to continue a web session across an app interruption (eg. incoming SMS that is read). Approach A: I have tried to store the contents of a UIWebView in NSUserDefaults, like this: NSData *webViewData = [NSKeyedArchiver archivedDataWithRootObject:webView]; [[NSUserDefaults standardUserDefaults] setObject:webViewData forKey:kDefaul...

Programmatically loading an object model created using NSCoding

Version 1.0 of an application has a data model, which is saved/loaded using the NSKeyed(Un)Archiver classes, as all model classes adhere to the NSCoding protocol. Say the following hierarchy exists: -> Houses (NSMutableArray) -> -> House (Custom Object) -> -> -> Color (3 ints, RGB) -> -> -> Number of Residents (int) Say that there are...

iPhone - Why does the documentation say UIImageView is NSCoding compliant?

Ideally an NSCoding compliant class will work as expected using encodeWithCoder: and initWithCoder: (at least I thought so till recently) without the developer having to bother about what goes on inside the routines (unless my idea of an NSCoding compliant class are totally screwed up!) The UIImageView class is NSCoding compliant. So I ...

Saving/loading a 2D C array with NSKeyedArchiver

Malloc like this int **terrain; terrain = malloc(sizeof(int*) * mapSize.x); for (int i = 0; i < mapSize.x; i++) { terrain[i] = malloc(mapSize.y * sizeof(int)); } Use it. Convert to NSdata like this before saving NSData *data=[NSData dataWithBytes:terrain length:(30*sizeof(int*) +30*30*sizeof(int) )]; [rootObject setValue:data ...

override classes variable, or at least variable type in objective-c / cocoa

My dilemma is as follows: I have a custom subclass of UIImage (I've added some serialization methods i.e. initWithCoder, encodeWithCoder), and I would like to apply my custom subclass as a variable to a UIImageView, or at least a subclass of UIImageView. As you are aware, UIImageView has a variable called "image", that is of type UII...

CGPathRef encoding

Is it possible to encode CGPathRef variables? I mean is there an encodeObject:forKey like method for CGPathRef variables? ...

Will longer keys make an NSKeyedArchiver file significantly longer

When I fill in the encodeWithCoder: for objective c classes for an iPhone app will it make make the archive file larger if I use long keys as opposed to short keys for all of my variables? For example if I use really long keys like this: [coder encodeBool:myBoolean forKey:@"My_Excesively_Long_Boolean_Key"]; will it make the archive f...

Archiving / Unarchiving results in initForReadingWithData incomprehensible archive

I've implemented an save on applicationWillTerminate and load on applicationWillFinishLoading. There is a complete object tree, all implement the NSCoding protocol and I've check the types I enter. One of the classes also stores an NSMutableData to the NSKeyedArchive, which I suspect might break unarchiving occasionally. Weirdly enough,...

Encoding an Objective-c Block?

Is it possible to encode an objective-c block with an NSKeyedArchiver? I dont think a Block object is NSCoding compliant, therefore [coder encodeObject:block forKey:@"block"] does not work? Any ideas? ...

How to persist and load an object which conforms to NSCoding protocol?

I have made an class which conforms to the NSCoding protocol and does all the encode and decode stuff. For my app, I simply want to persist an object from that class to the device and the next time when the app launches, I want to load that object back into memory. Basically it's just an class which holds some user input information. F...

What's the fastest way to determine if a file adheres to a particular class's NSCoding implementation?

Given: An application that accesses a directory of files: some plain text, some binary files that adhere to a particular NSCoding implementation, and perhaps other binary files it simply doesn't understand how to process. I want to: Be able to figure out which of the files in that directory adhere to my NSCoding class, and I'd prefer no...

[iPhone]Objective C, objects which do not conform to NSCoding. How to write them to a file.

Hi, I am using an Objective c class, a subclass of NSObject. This class cannot be modified. I have an instance of this class that I wish to write to a file which can be retrieved and later reinstate. The object does not conform to NSCoding. To sum up, I need to save an instance of a class to a file which can be retrieved later, without ...

iPhone -- initialization partly by NSKeyedUnarchiver and partly by other means

I have an object myObj, which is an instance of a class MyClass. Some of its instance variables always have their initial values passed in by the calling code. Other instance variables will be initialized in one of two ways. For an instanceArray of type NSMutableArray, the possibilities are either instanceArray = [[NSMutableArray all...

NSCoding and ostream

Is there a better way to serialize an ObjC object than using /NSKeyedArchive? I need to distribute the object through a C++ std:ostream-like object to put on another computer. The object has over 122 members of various types... for which wants me to [coder encodeObject: (id) forKey: @"blah"]; for all of them... Does anyone have a...

Saving an NSMutableArray of custom Objects

I have a custom class that is used as a wrapper to an NSMutableArray @interface AllCourses : NSObject { NSMutableArray *arrClasses; } The array above stores Objects of another custom class. @interface Course : NSObject { NSString *className; NSString *classGrade; NSInteger creditHours; } I use the method below to add Course obje...

[Iphone] - Problem in saving file using NSCoding

Hi everybody, I've a problem with Iphone programming... I've a NSMutableArray containing object of type "MyClass". MyClass has some parameters, like NSNumber and NSString. I've followed the Apple Tutorial about coding and decoding object using NSCoding, but when I try to decode the file I've stored, the NSMutableArray contain object of...

Can I do this?? Trying to load an object from within itself.

Hi all! I have an object which conforms to the NSCoding protocol. The object contains a method to save itself to memory, like so: - (void)saveToFile { NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver encodeObject:self forKey:kData...

NSCoding Serialization of iPhone NavigationController stack.

EDIT: I seem to have found something that's helped. I retained the ivar "stack" and now it seems to be working I have been serializing several custom NSObject classes without issue. Now I'd like to serialize my NavigationController stack. Each viewController only needs a couple of properties saved in order to rebuild the navigation ...

Better to archive 1 large object or several smaller objects with NSCoder?

I have a need to archive an array of objects of several different types. Each object has its own instance vars. Is it better to create singleton object with an array that holds ~20 archived objects, or have a single archived object that has an array of all the other objects? Sorry if that's confusing, but I'm a bit confused myself. ...