Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 09-05-2010, 02:14 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Las Vegas
Posts: 9
JR2760 is on a distinguished road
Default Problem encoding archiving and saving data

Hello,
I'm trying to archive and save an instance of a (custom) object:

-(void) saveProfile{
ProfileObj *profile = [[ProfileObj alloc] init];
profile = Player[0];

NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:profile forKey:kDatakey];
[archiver finishEncoding];
[data writeToFile:[self pathOfFile] atomically:YES];
[profile release];
[archiver release];
[data release];
}

for debugging purposes my ProfileObj currently only has one NSString variable that is being saved, and the code runs fine while that NSString is nil (currently loaded from Player[0]) but when the string has data the app crashes at [archiver encodeObject:profile forKey:kDatakey]; and i cannot figure out why or how to fix it. This is my first time ever trying to save data and any help would be greatly appreciated!


#pragma mark NSCoding
-(void) encodeWithCoder:(NSCoder *)encoder {
[encoder endodeObject:Name forKey: kNameKey];
}
-(id) initWithCoder:(NSCoder *)decoder {
if (self = [super init]){
self.Name = [decoder decodeObjectForKey:kNameKey];
}
return self;
}
#pragma mark -
#pragma mark NSCopying
-(id)copyWithZone:(NSZone *)zone{
ProfileObj *copy = [[[self class] allocWithZone: zone] init];
copy.Name = [[self.Name copyWithZone:zone] autorelease];
return copy;
}
This is some code within ProfileObj.h, the one string i'm trying to save is called Name.
JR2760 is offline   Reply With Quote
Reply

Bookmarks

Tags
archive, data, encoding, object, save

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 379
15 members and 364 guests
AragornSG, ChrisYates, coolman, davejas69, givensur, hussain1982, iAppDeveloper, jbro, Kryckter, locombiano89, Mah6447, Meoz, stanny, Tomsky, WeaselPig
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,646
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, locombiano89
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:45 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0