Search Results

Search found 34 results on 2 pages for 'nskeyedarchiver'.

Page 1/2 | 1 2  | Next Page >

  • NSKeyedArchiver on NSArray has large size overhead

    - by redguy
    I'm using NSKeyedArchiver in Mac OS X program which generates data for iPhone application. I found out that by default, resulting archives are much bigger than I expected. Example: NSMutableArray * ar = [NSMutableArray arrayWithCapacity:10]; for (int i = 0; i < 100000; i++) { NSString * s = [NSString stringWithFormat:@"item%06d", i]; [ar addObject:s]; } [NSKeyedArchiver archiveRootObject:ar toFile: @"NSKeyedArchiver.test"]; This stores 10 * 100000 = 1M bytes of useful data, yet the size of the resulting file is almost three megabytes. The overhead seems to be growing with number of items in the array. In this case, for 1000 items, the file was about 22k. "file" reports that it is a "Apple binary property list" (not the XML format). Is there an simple way to prevent this huge overhead? I wanted to use the NSKeyedArchiver for the simplicity it provides. I can write data to my own, non-generic, binary format, but that's not very elegant. Also, aggregating the data into large chunks and feeding these to the NSKeyedArchiver should work, but again, that kinda beats the point of using simple&easy&ready to use archiver. Am I missing some method call or usage pattern that would reduce this overhead?

    Read the article

  • Why isnt my data persisting with nskeyedarchiver?

    - by aking63
    Im just working on what should be the "finishing touches" of my first iPhone game. For some reason, when I save with NSKeyedArchiver/Unarchiver, the data seems to load once and then gets lost or something. Here's what I've been able to deduce: When I save in this viewController, pop to the previous one, and then push back into this one, the data is saved and prints as I want it to. But when I save in this viewController, then push a new one and pop back into this one, the data is lost. Any idea why this might be happening? Do I have this set up all wrong? I copied it from a book months ago. Here's the methods I use to save and load. - (void) saveGameData { NSLog(@"LS:saveGameData"); // SAVE DATA IMMEDIATELY NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *gameStatePath = [documentsDirectory stringByAppendingPathComponent:@"gameState.dat"]; NSMutableData *gameSave= [NSMutableData data]; NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:gameSave]; [encoder encodeObject:categoryLockStateArray forKey:kCategoryLockStateArray]; [encoder encodeObject:self.levelsPlist forKey:@"levelsPlist"]; [encoder finishEncoding]; [gameSave writeToFile:gameStatePath atomically:YES]; NSLog(@"encoded catLockState:%@",categoryLockStateArray); } - (void) loadGameData { NSLog(@"loadGameData"); // If there is a saved file, perform the load NSMutableData *gameData = [NSData dataWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"gameState.dat"]]; // LOAD GAME DATA if (gameData) { NSLog(@"-Loaded Game Data-"); NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:gameData]; self.levelsPlist = [unarchiver decodeObjectForKey:@"levelsPlist"]; categoryLockStateArray = [unarchiver decodeObjectForKey:kCategoryLockStateArray]; NSLog(@"decoded catLockState:%@",categoryLockStateArray); } // CREATE GAME DATA else { NSLog(@"-Created Game Data-"); self.levelsPlist = [[NSMutableDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLevelsPlist ofType:@"plist"]]; } if (!categoryLockStateArray) { NSLog(@"-Created categoryLockStateArray-"); categoryLockStateArray = [[NSMutableArray alloc] initWithCapacity:[[self.levelsPlist allKeys] count]]; for (int i=0; i<[[self.levelsPlist allKeys] count]; i++) { [categoryLockStateArray insertObject:[NSNumber numberWithBool:FALSE] atIndex:i]; } } // set the properties of the categories self.categoryNames = [self.levelsPlist allKeys]; NUM_CATEGORIES = [self.categoryNames count]; thisCatCopy = [[NSMutableDictionary alloc] initWithDictionary:[[levelsPlist objectForKey:[self.categoryNames objectAtIndex:pageControl.currentPage]] mutableCopy]]; NUM_FINISHED = [[thisCatCopy objectForKey:kNumLevelsBeatenInCategory] intValue]; }

    Read the article

  • NSKeyedArchiver save method ( that i made) crashed the iphone simulator

    - by Kevin
    i saw this approach on a tutorial, and the message is working for their example but when i implement this it does not work. from what i can tell the iphone simulator crashes when i do a [ self saveSettingsData]. TheSettings is class object that i declare and initialize in the appdelagate with these methods. the error says terminating due to uncaught exception. i am new to the iphone sdk and objective, so i really can't figure out what is going on thanks to any one who can help, i am ready to literally pull my hair out. (NSString *) SettingsDataFilePath { NSString * settingsDataFilePath ; NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ; NSString * documentsDirectory = [paths objectAtIndex:0] ; settingsDataFilePath = [[documentsDirectory stringByAppendingPathComponent: @"SetggggtingsData.plist" ] retain] ; return settingsDataFilePath ; } (void) saveSettingsData { [NSKeyedArchiver archiveRootObject:[TheSettings copy] toFile:[self SettingsDataFilePath]] ;

    Read the article

  • UIImagePickerController Causes my app to crash!

    - by Flafla2
    In my app, a user can select an image, change the picture of a UIImageView to the new imge, and save the image to NSUserDefaults using NSKeyedArchiver. When the user selects the image the app immediately crashes! Here is my code - - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; if ([[NSUserDefaults standardUserDefaults] integerForKey:@"PictureKey"] == 1) { UIImage *previmage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; [prevbutton setImage:previmage]; NSData *previmagedata = [NSKeyedArchiver archivedDataWithRootObject:previmage]; [[NSUserDefaults standardUserDefaults] setObject:previmagedata forKey:@"PrevImage"]; } else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"PictureKey"] == 2) { UIImage *nextimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; [nextbutton setImage:nextimage]; NSData *nextimagedata = [NSKeyedArchiver archivedDataWithRootObject:nextimage]; [[NSUserDefaults standardUserDefaults] setObject:nextimagedata forKey:@"NextImage"]; }else { UIImage *optionsimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; [moreoptionsbutton setImage:optionsimage]; NSData *optimagedata = [NSKeyedArchiver archivedDataWithRootObject:optionsimage]; [[NSUserDefaults standardUserDefaults] setObject:optimagedata forKey:@"OptionsImage"]; } } Thanks in advance!

    Read the article

  • What happens with unarchived objects?

    - by Dane Man
    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 resources in apple but I haven't seen a thorough explination of proper usage of NSKeyedArchiver. Please Help.

    Read the article

  • Storing arrays in NSUserDefaultsController

    - by neoneye
    Currently I use NSUserDefaults and I'm interested in using NSUserDefaultsController, so that I get notifications when things change. Below is my current code. items = /* NSArray of MYItem's */; NSData* data = [NSKeyedArchiver archivedDataWithRootObject:items]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:kMYItems]; How should I rework my code to store items in NSUserDefaultsController ? Is NSKeyedArchiver the smartest way to store arrays? @interface MYItem : NSObject <NSCoding> { NSString* name; NSString* path; } @property (copy) NSString* name; @property (copy) NSString* path; @end @implementation MYItem @synthesize name, path; -(void)encodeWithCoder:(NSCoder*)coder { [coder encodeObject:name forKey:@"name"]; [coder encodeObject:path forKey:@"path"]; } -(id)initWithCoder:(NSCoder*)coder { [super init]; [self setName:[coder decodeObjectForKey:@"name"]]; [self setPath:[coder decodeObjectForKey:@"path"]]; return self; } @end

    Read the article

  • Fast (de)serialization on iPhone

    - by Jacob Kuypers
    I'm developing a game/engine for iPhone OS. It's the first time I'm using Objective-C. I made my own binary format for geometry data and for textures I'm focusing on PVRTC. That should be the optimal approach as far as speed and space are concerned. I really want to keep loading time to a minimum and - if possible - be able to save very fast as well. So now I'm trying to make my "Entity" stuff persistent without sacrificing performance. First I wanted to use NSKeyedArchiver. From what I've heard, it's not very fast. Also, what I want to serialize is mostly structs made of floats with some ints and strings, so there isn't really a need for all that "object graph" overhead. NSArchiver would have been more appropriate, but they kicked that off the iphone for some reason. So now I'm thinking about making my own serialization scheme again. Am I wrong in thinking that NSKeyedArchiver is slow (I only read that, haven't tested it myself)? If so, what's the best way to encode/decode structs (with no pointers, mostly floats) without sacrificing speed?

    Read the article

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

    - by mystify
    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. For example the user starts writing a text but then quits the app. Next time I want to load that data object. I guess I need NSKeyedArchiver? Is there a good tutorial on this? How do I do that?

    Read the article

  • Where'd my sounds go?

    - by Dane Man
    In my Row class I have the initWithCoder method and everything restored in that method works fine, but only within the method. After the method is called I loose an array of sounds that is in my Row class. The sounds class also has the initWithCoder method, and the sound plays fine but only in the Row class initWithCoder method. After decoding the Row object, the sound array disappears completely and is unable to be called. Here's my source for the initWithCoder: - (id) initWithCoder:(NSCoder *)coder { ... soundArray = [coder decodeObjectForKey:@"soundArray"]; NSLog(@"%d",[soundArray count]); return self; } the log shows the count as 8 like it should (this is while unarchiving). Then the row object I create gets assigned. And the resulting row object no longer has a soundArray. [NSKeyedArchiver archiveRootObject:row toFile:@"DefaultRow"]; ... row = [NSKeyedUnarchiver unarchiveObjectWithFile:@"DefaultRow"]; So now whenever I call the soundArray it crashes. //ERROR IS HERE NSLog(@"%d",[[row soundArray] count]); Help please (soundArray is an NSMutableArray).

    Read the article

  • Archiver Securing SQLite Data without using Encryption on iPhone

    - by Redrocks
    I'm developing an iphone app that uses Core Data with a SQLite data store and lots of images in the resource bundle. I want a "simple" way to obfuscate the file structure of the SQLite database and the image files to prevent the casual hacker/unscrupulous developer from gaining access to them. When the app is deployed, the database file and image files would be obfuscated. Upon launching the app it would read in and un-obfuscate the database file, write the un-obfuscated version to the users "tmp" directory for use by core data, and read/un-obfuscate image files as needed. I'd like to apply a simple algorithm to the files that would somehow scramble/manipulate the file data so that the sqlite database data isn't discernible when the db is opened in a text editor and so that neither is recognized by other applications (SQLite Manager, Photoshop, etc.) It seems, from the information I've read, that I could use NSFileManager, NSKeyedArchiver, and NSData to accomplish this but I'm not sure how to proceed. Been developing software for many years but I'm new to everything CocoaTouch, Mac and iPhone. Also never had to secure/encrypt my data so this is new. Any thoughts, suggestions, or links to solutions are appreciated.

    Read the article

  • NSKeyedUnarchiver chokes when trying to unarchive more than one object

    - by ajduff574
    We've got a custom matrix class, and we're attempting to archive and unarchive an NSArray containing four of them. The first seems to get unarchived fine (we can see that initWithCoder is called once), but then the program simply hangs, using 100% CPU. It doesn't continue or output any errors. These are the relevant methods from the matrix class (rows, columns, and matrix are our only instance variables): -(void)encodeWithCoder:(NSCoder*) coder { float temp[rows * columns]; for(int i = 0; i < rows; i++) { for(int j = 0; j < columns; j++) { temp[columns * i + j] = matrix[i][j]; } } [coder encodeBytes:(const void *)temp length:rows*columns*sizeof(float) forKey:@"matrix"]; [coder encodeInteger:rows forKey:@"rows"]; [coder encodeInteger:columns forKey:@"columns"]; } -(id)initWithCoder:(NSCoder *) coder { if (self = [super init]) { rows = [coder decodeIntegerForKey:@"rows"]; columns = [coder decodeIntegerForKey:@"columns"]; NSUInteger * len; *len = (unsigned int)(rows * columns * sizeof(float)); float * temp = (float * )[coder decodeBytesForKey:@"matrix" returnedLength:len]; matrix = (float ** )calloc(rows, sizeof(float*)); for (int i = 0; i < rows; i++) { matrix[i] = (float*)calloc(columns, sizeof(float)); } for(int i = 0; i < rows *columns; i++) { matrix[i / columns][i % columns] = temp[i]; } } return self; } And this is really all we're trying to do: NSArray * weightMatrices = [NSArray arrayWithObjects:w1,w2,w3,w4,nil]; [NSKeyedArchiver archiveRootObject:weightMatrices toFile:@"weights.archive"]; NSArray * newWeights = [NSKeyedUnarchiver unarchiveObjectWithFile:@"weights.archive"]; What's driving us crazy is that we can archive and unarchive a single matrix just fine. We've done so (successfully) with a matrix many times larger than these four combined.

    Read the article

  • game state singleton cocos2d, initWithEncoder always returns null

    - by taber
    Hi, I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void) loadState; +(void) saveState; @end ... and GameState.m: #import "GameState.h" #import "Constants.h" @implementation GameState static GameState *sharedState = nil; @synthesize level, score, seenInstructions; -(void)dealloc { [super dealloc]; } -(id)init { if(!(self = [super init])) return nil; level = 1; score = 0; seenInstructions = NO; return self; } +(void)loadState { @synchronized([GameState class]) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; Boolean saveFileExists = [[NSFileManager defaultManager] fileExistsAtPath:saveFile]; if(!sharedState) { sharedState = [GameState sharedState]; } if(saveFileExists == YES) { [sharedState release]; sharedState = [[NSKeyedUnarchiver unarchiveObjectWithFile:saveFile] retain]; } // at this point, sharedState is null, saveFileExists is 1 if(sharedState == nil) { // this always occurs CCLOG(@"Couldn't load game state, so initialized with defaults"); sharedState = [self sharedState]; } } } +(void)saveState { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; [NSKeyedArchiver archiveRootObject:[GameState sharedState] toFile:saveFile]; } +(GameState *)sharedState { @synchronized([GameState class]) { if(!sharedState) { [[GameState alloc] init]; } return sharedState; } return nil; } +(id)alloc { @synchronized([GameState class]) { NSAssert(sharedState == nil, @"Attempted to allocate a second instance of a singleton."); sharedState = [super alloc]; return sharedState; } return nil; } +(id)allocWithZone:(NSZone *)zone { @synchronized([GameState class]) { if(!sharedState) { sharedState = [super allocWithZone:zone]; return sharedState; } } return nil; } ... -(void)encodeWithCoder:(NSCoder *)coder { [coder encodeInt:level forKey:@"level"]; [coder encodeInt:score forKey:@"score"]; [coder encodeBool:seenInstructions forKey:@"seenInstructions"]; } -(id)initWithCoder:(NSCoder *)coder { CCLOG(@"initWithCoder called"); self = [super init]; if(self != nil) { CCLOG(@"initWithCoder self exists"); level = [coder decodeIntForKey:@"level"]; score = [coder decodeIntForKey:@"score"]; seenInstructions = [coder decodeBoolForKey:@"seenInstructions"]; } return self; } @end ... I'm saving the state on app exit, like this: - (void)applicationWillTerminate:(UIApplication *)application { [GameState saveState]; [[CCDirector sharedDirector] end]; } ... and loading the state when the app finishes loading, like this: - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [GameState loadState]; ... } I've tried moving around where I call loadState too, for example in my main CCScene, but that didn't seem to work either. Thanks again in advance.

    Read the article

  • Does NSKeyedUnarchiver autorelease?

    - by Lee Probert
    I'm doing some archiving to a property list and when I unarchive my data using NSKeyedUnarchiver I find that my app crashes if I release the object afterward. I was wondering if the finishDecoding message also autoreleases the object. Seems weird that it crashes when I release it.

    Read the article

  • Loading from archive?

    - by fuzzygoat
    Can anyone point me in the right direction, I have two sets of load/save methods below that I am playing with to save an array of objects out to disk and then load them back in. I am getting a little confused after calling "saveMoons" how I should go about loading that data back in ... any pointers would be great. -(void)saveMoons:(NSString *)savePath { NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [moons encodeWithCoder:archiver]; [archiver finishEncoding]; [data writeToFile:savePath atomically:YES]; [data release]; [archiver release]; } -(void)loadMoons:(NSString *)loadPath { NSMutableData *data = [[NSMutableData alloc] initWithContentsOfFile:loadPath]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; // [self setMoons:[unarchiver ??????]]; } . // ------------------------------------------------------------------- ** // SIMPLER // ------------------------------------------------------------------- ** -(void)saveMoons_SIMPLE:(NSString *)savePath { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:moons]; [data writeToFile:savePath atomically:YES]; } -(void)loadMoons_SIMPLE:(NSString *)loadPath { [self setMoons:[NSKeyedUnarchiver unarchiveObjectWithFile:loadPath]]; } // ------------------------------------------------------------------- ** // // ------------------------------------------------------------------- ** gary

    Read the article

  • How to load object after saving with encodeWithCoder?

    - by fuzzygoat
    EDIT_002: Further rewrite: if I save using the method below how would the method to load it back in look? (moons is an NSMutableArray of NSNumbers) // ------------------------------------------------------------------- ** // METHOD_002 // ------------------------------------------------------------------- ** -(void)saveMoons:(NSString *)savePath { NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [moons encodeWithCoder:archiver]; [archiver finishEncoding]; [data writeToFile:savePath atomically:YES]; [archiver release]; [data release]; } EDIT_003: Found it, my problem was that I was using ... [moons encodeWithCoder:archiver]; where I should have been using ... [archiver encodeObject:moons]; Hence the loader would look like: -(void)loadMoons_V3:(NSString *)loadPath { NSData *data = [[NSData alloc] initWithContentsOfFile:loadPath]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; [self setMoons:[unarchiver decodeObject]]; [unarchiver finishDecoding]; [unarchiver release]; [data release]; } gary

    Read the article

  • iPhone - archiving array of custom objects

    - by Dylan
    I've been trying for hours and I cannot solve this problem. I'm making an app that saves unfinished Chess Games, so I'm trying to write an array to a file. This is what the array is, if it makes sense: -NSMutableArray savedGames --GameSave a ---NSMutableArray board; ----Piece a, b, c, etc. -----some ints ---NSString whitePlayer, blackPlayer; ---int playerOnTop, turn; --GameSave b ---NSMutableArray board; ----Piece a, b, c, etc. -----some ints ---NSString whitePlayer, blackPlayer; ---int playerOnTop, turn; etc. And these are my NSCoding methods: GameSave.m - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:whitePlayer forKey:@"whitePlayer"]; [coder encodeObject:blackPlayer forKey:@"blackPlayer"]; [coder encodeInt:playerOnTop forKey:@"playerOnTop"]; [coder encodeInt:turn forKey:@"turn"]; [coder encodeObject:board forKey:@"board"]; } - (id)initWithCoder:(NSCoder *)coder { self = [[GameSave alloc] init]; if (self != nil) { board = [coder decodeObjectForKey:@"board"]; whitePlayer = [coder decodeObjectForKey:@"whitePlayer"]; blackPlayer = [coder decodeObjectForKey:@"blackPlayer"]; playerOnTop = [coder decodeIntForKey:@"playerOnTop"]; turn = [coder decodeIntForKey:@"turn"]; } return self; } Piece.m - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeInt:color forKey:@"color"]; [coder encodeInt:piece forKey:@"piece"]; [coder encodeInt:row forKey:@"row"]; [coder encodeInt:column forKey:@"column"]; } - (id)initWithCoder:(NSCoder *)coder { self = [[Piece alloc] init]; if (self != nil) { color = [coder decodeIntForKey:@"color"]; piece = [coder decodeIntForKey:@"piece"]; row = [coder decodeIntForKey:@"row"]; column = [coder decodeIntForKey:@"column"]; } return self; } And this is the code that tries to archive and save to file: - (void)saveGame { ChessSaverAppDelegate *delegate = (ChessSaverAppDelegate *) [[UIApplication sharedApplication] delegate]; [[delegate gameSave] setBoard:board]; NSMutableArray *savedGames = [NSKeyedUnarchiver unarchiveObjectWithFile:[self dataFilePath]]; if (savedGames == nil) { [NSKeyedArchiver archiveRootObject:[delegate gameSave] toFile:[self dataFilePath]]; } else { [savedGames addObject:[delegate gameSave]]; [NSKeyedArchiver archiveRootObject:savedGames toFile:[self dataFilePath]]; } } - (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:@"gameSaves.plist"]; } Sorry, here's the problem: After setting some breakpoints, an error is reached after this line from -saveGame: [NSKeyedArchiver archiveRootObject:savedGames toFile:[self dataFilePath]]; And this is what shows up in the console: 2010-05-11 17:04:08.852 ChessSaver[62065:207] *** -[NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x3d3cd30 2010-05-11 17:04:08.891 ChessSaver[62065:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x3d3cd30' 2010-05-11 17:04:08.908 ChessSaver[62065:207] Stack: ( 32339035, 31077641, 32720955, 32290422, 32143042, 238843, 25827, 238843, 564412, 342037, 238843, 606848, 17686, 2733061, 4646817, 2733061, 3140430, 3149167, 3144379, 2837983, 2746312, 2773089, 41684313, 32123776, 32119880, 41678357, 41678554, 2777007, 9884, 9738 ) If it matters, -saveGame is called from a UIBarButton in a navigation controller. Any help is appreciated, thanks.

    Read the article

  • Problem with saveToFile

    - by zp26
    Hi, I have a problem with a NSData writeToFile. I have implemented the code below but i have an anomaly. When i run my program on the simulator, the new file is created and the informations are stored; when i build the app in my device , the file isn't created. The debug don't give me any error but don/t save anything. Can you help me? Thanks so much and sorry for my english. -(void)saveXML:(NSString*)name:(float)x:(float)y:(float)z{ NSMutableData *data = [NSMutableData data]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0]; [archiver encodeFloat:x forKey:@"x"]; [archiver encodeFloat:y forKey:@"y"]; [archiver encodeFloat:z forKey:@"z"]; [archiver encodeObject:name forKey:@"name"]; [archiver finishEncoding]; BOOL result = [data writeToFile:@"XML Position" atomically:YES]; if(result) [self updateTextView:@"success"]; [archiver release]; }

    Read the article

  • Looking for the log file on iPhone

    - by zp26
    Hi, I have a problem. I have the code below for save a data on file. I build my app on the device, and run. The result variable is TRUE, but i don't find the file on the my iPhone device. Can you help me? Thank and sorry for my english XP -(void)saveXML:(NSString*)name:(float)x:(float)y:(float)z{ NSMutableData *data = [NSMutableData data]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0]; [archiver encodeFloat:x forKey:@"x"]; [archiver encodeFloat:y forKey:@"y"]; [archiver encodeFloat:z forKey:@"z"]; [archiver encodeObject:name forKey:@"name"]; [archiver finishEncoding]; NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"XML Position"]; BOOL result = [data writeToFile:filePath atomically:YES]; if(result) [self updateTextView:@"success"]; [archiver release]; }

    Read the article

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

    - by Smikey
    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:kDataKey]; [archiver finishEncoding]; [data writeToFile:[self dataFilePath] atomically:YES]; [archiver release]; [data release]; } This works just fine. But I would also like to initialise an empty version of this object and then call its own 'Load' method to load whatever data exists on file into its variables. So I've created the following: - (void)loadFromFile { NSString *filePath = [self dataFilePath]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; self = [unarchiver decodeObjectForKey:kDataKey]; [unarchiver finishDecoding]; } } Now this second method doesn't manage to load any variables. Is this line not possible perhaps? self = [unarchiver decodeObjectForKey:kDataKey]; Ultimately I would like to use the code like this: One viewController takes user entered input, creates an object and saves it to memory using [anObject saveToFile]; And a second viewController creates an empty object, then initialises its values to those stored on file by calling: [emptyObject loadFromFile]; Any suggestions on how to make this work would be hugely appreciated. Thanks :) Michael

    Read the article

  • iPhone Serialization problem

    - by Jenicek
    Hi, I need to save my own created class to file, I found on the internet, that good approach is to use NSKeyedArchiver and NSKeyedUnarchiver My class definition looks like this: @interface Game : NSObject <NSCoding> { NSMutableString *strCompleteWord; NSMutableString *strWordToGuess; NSMutableArray *arGuessedLetters; //This array stores characters NSMutableArray *arGuessedLettersPos; //This array stores CGRects NSInteger iScore; NSInteger iLives; NSInteger iRocksFallen; BOOL bGameCompleted; BOOL bGameOver; } I've implemented methods initWithCoder: and encodeWithCoder: this way: - (id)initWithCoder:(NSCoder *)coder { if([coder allowsKeyedCoding]) { strCompleteWord = [[coder decodeObjectForKey:@"CompletedWord"] copy]; strWordToGuess = [[coder decodeObjectForKey:@"WordToGuess"] copy]; arGuessedLetters = [[coder decodeObjectForKey:@"GuessedLetters"] retain]; // arGuessedLettersPos = [[coder decodeObjectForKey:@"GuessedLettersPos"] retain]; iScore = [coder decodeIntegerForKey:@"Score"]; iLives = [coder decodeIntegerForKey:@"Lives"]; iRocksFallen = [coder decodeIntegerForKey:@"RocksFallen"]; bGameCompleted = [coder decodeBoolForKey:@"GameCompleted"]; bGameOver = [coder decodeBoolForKey:@"GameOver"]; } else { strCompleteWord = [[coder decodeObject] retain]; strWordToGuess = [[coder decodeObject] retain]; arGuessedLetters = [[coder decodeObject] retain]; // arGuessedLettersPos = [[coder decodeObject] retain]; [coder decodeValueOfObjCType:@encode(NSInteger) at:&iScore]; [coder decodeValueOfObjCType:@encode(NSInteger) at:&iLives]; [coder decodeValueOfObjCType:@encode(NSInteger) at:&iRocksFallen]; [coder decodeValueOfObjCType:@encode(BOOL) at:&bGameCompleted]; [coder decodeValueOfObjCType:@encode(BOOL) at:&bGameOver]; } return self; } - (void)encodeWithCoder:(NSCoder *)coder { if([coder allowsKeyedCoding]) { [coder encodeObject:strCompleteWord forKey:@"CompleteWord"]; [coder encodeObject:strWordToGuess forKey:@"WordToGuess"]; [coder encodeObject:arGuessedLetters forKey:@"GuessedLetters"]; //[coder encodeObject:arGuessedLettersPos forKey:@"GuessedLettersPos"]; [coder encodeInteger:iScore forKey:@"Score"]; [coder encodeInteger:iLives forKey:@"Lives"]; [coder encodeInteger:iRocksFallen forKey:@"RocksFallen"]; [coder encodeBool:bGameCompleted forKey:@"GameCompleted"]; [coder encodeBool:bGameOver forKey:@"GameOver"]; } else { [coder encodeObject:strCompleteWord]; [coder encodeObject:strWordToGuess]; [coder encodeObject:arGuessedLetters]; //[coder encodeObject:arGuessedLettersPos]; [coder encodeValueOfObjCType:@encode(NSInteger) at:&iScore]; [coder encodeValueOfObjCType:@encode(NSInteger) at:&iLives]; [coder encodeValueOfObjCType:@encode(NSInteger) at:&iRocksFallen]; [coder encodeValueOfObjCType:@encode(BOOL) at:&bGameCompleted]; [coder encodeValueOfObjCType:@encode(BOOL) at:&bGameOver]; } } And I use these methods to archive and unarchive data: [NSKeyedArchiver archiveRootObject:currentGame toFile:strPath]; Game *currentGame = [NSKeyedUnarchiver unarchiveObjectWithFile:strPath]; I have two problems. 1) As you can see, lines with arGuessedLettersPos is commented, it's because every time I try to encode this array, error comes up(this archiver cannot encode structs), and this array is used for storing CGRect structs. I've seen solution on the internet. The thing is, that every CGRect in the array is converted to an NSString (using NSStringFromCGRect()) and then saved. Is it a good approach? 2)This is bigger problem for me. Even if I comment this line and then run the code successfully, then save(archive) the data and then try to load (unarchive) them, no data is loaded. There aren't any error but currentGame object does not have data that should be loaded. Could you please give me some advice? This is first time I'm using archivers and unarchivers. Thanks a lot for every reply.

    Read the article

1 2  | Next Page >