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 > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-17-2011, 11:16 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 3
priyahari is on a distinguished road
Default Application exits when NSKeyedUnarchiver is called!

Hello,

I am trying to create a simple application to list/add/search/delete students. It is window-based application and I am using NSKeyedArchiver for data persistence.

I call NSKeyedArchiver when user tries to add a student and it works fine. It creates a file and writes into the file. But when I use NSKeyedUnarchiver to list the students the appln responds differently. It lists the students(goes to next view) sometimes and the application exits(without going to next view)other times.

Not sure why this is happening. If I comment out NSKeyedUnarchiver line it works perfectly fine but I wont be able to retrieve stored data. I even tried try,catch block but the logs indicate this.

StudentList(16260,0xa083e540) malloc: *** error for object 0x4e23000: pointer being freed was not allocated
I checked each and every release I make a release only when alloc is called.

Please find the code from Appdelegate.m below:

- (void)onButton1Clickedid)sender
{
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

view.backgroundColor = [UIColor lightGrayColor];
[window addSubview:view];

CGRect butRect = { 60.0, 400.0, 160.0, 40.0 };
UIButton *button = [[UIButton alloc] initWithFrame:butRect];

[button setBackgroundColor:[UIColor blueColor]];

[button setTitle:@"Back" forState: (UIControlState)UIControlStateNormal];

[button addTarget:self action:@selector(closeMe forControlEvents:UIControlEventTouchUpInside];

[view addSubview:button];

[button release];


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 100.0, 200.0, 30.0)];

NSMutableArray *keyArray=[[NSMutableArray alloc] init];

@try
{
keyArray = [NSKeyedUnarchiver unarchiveObjectWithFile:@"/Users/priyahari/Documents/testfile.txt"];
}

@catch (NSString *stringException)
{
NSLog(@"provide some logs here");
}

if(keyArray != nil)
{
for(Student *s in keyArray)
{
label.text = [s fname]; //trying to print firstname alone
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
}
}
else
{
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];

}

[label release];
[keyArray release];
[view release];
}



Any help would be greatly appreciated. Thanks!
priyahari is offline   Reply With Quote
Old 10-17-2011, 11:26 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 3
priyahari is on a distinguished road
Default

StudentArray.m

//For saving
- (void) encodeWithCoder: (NSCoder *) coder
{
[coder encodeObject:fname forKey:@"fname"];
[coder encodeObject:lname forKey:@"lname"];
[coder encodeObject:ssn forKey:@"ssn"];
[coder encodeObjectno forKey:@"pno"];
[coder encodeObject:address forKey:@"address"];
}


//For reading
-(id) initWithCoderNSCoder *) coder
{
fname=[[coder decodeObjectForKey: @"fname"]retain];
lname=[[coder decodeObjectForKey: @"lname"]retain];
ssn=[[coder decodeObjectForKey: @"ssn"]retain];
pno=[[coder decodeObjectForKey: @"pno"]retain];
address=[[coder decodeObjectForKey: @"address"]retain];


return self;
}
priyahari is offline   Reply With Quote
Reply

Bookmarks

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: 479
14 members and 465 guests
AlanFloyd, andyzaharia, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, mutantskin, Paul Slocum, tiendung2992, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,684
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tiendung2992
Powered by vBadvanced CMPS v3.1.0

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