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

View Single Post
Old 12-20-2008, 06:29 PM   #6 (permalink)
ipodtouchmaster05
Registered Member
 
Join Date: Sep 2008
Posts: 180
ipodtouchmaster05 is on a distinguished road
Default

Quote:
Originally Posted by PhoneyDeveloper View Post
There are a number of memory leaks and other oddnesses in this code.

Objects created with mutableCopy must be released, yours are not. Objects created with alloc/init, like your assiString, must be released, yours is not.

This line is wrong and will crash:

Code:
NSArray *keys = [NSArray arrayWithObjects:[nextDict2 allKeys]];
arrayWithObjects is a varargs function that expects a nil terminated list of objects, you've only passed a single object, so it will crash. It is also wrong because there is no need to convert one array into another array, which seems to be what you're trying to do. This would be the usual way to get an array of the keys:

Code:
NSArray* keys = [nextDict2 allKeys];
There is no need to convert a string into another string with stringWithFormat. Code like the following is just weird:

Code:
NSString *assiString = [[NSString alloc] initWithFormat:@"%@", [assignmentsArray objectAtIndex:indexPath.row]];
Try this instead:

Code:
NSString *assiString = [assignmentsArray objectAtIndex:indexPath.row];
You don't need to release the string in this case.

I would not have the synchronize call inside the loop.
thanks for the suggestions, but I tried them and it still crashes, but it ha an error now but i cant find out what it means so here is my code:

Code:
- (void) cancelPressed {
	HWPlannerAppDelegate *appDelegate = (HWPlannerAppDelegate*)[[UIApplication sharedApplication] delegate];
	[appDelegate resetAll];
	
	
	NSMutableDictionary *startDict2 = [NSMutableDictionary dictionaryWithDictionary:[[[NSUserDefaults standardUserDefaults] objectForKey:nameString] mutableCopy]];
	NSMutableDictionary *nextDict2 = [NSMutableDictionary dictionaryWithDictionary:[[startDict2 objectForKey:@"Assignments"] mutableCopy]];
	
	if ([nextDict2 count] > 0) {
		NSArray *keys = [nextDict2 allKeys];
		NSString *assiString = [NSString stringWithFormat:@"%@", [nameAndDesc objectAtIndex:0]];

		int k = 0;
		for (k = 0;k < [keys count];k++) {
			if ([assiString isEqualToString:[NSString stringWithFormat:@"%@", [keys objectAtIndex:k]]]) {
				[nextDict2 removeObjectForKey:[NSString stringWithFormat:@"%@", [keys objectAtIndex:k]]];
			}
		}
		
		[startDict2 setObject:nextDict2 forKey:@"Assignments"];
		[[NSUserDefaults standardUserDefaults] setObject:startDict2 forKey:nameString];
		[[NSUserDefaults standardUserDefaults] synchronize];
	}
	
	[reloadTimer invalidate];
	[self removeFromSuperview];
}
and the error i am getting is:

Code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButtonContent objectAtIndex:]: unrecognized selector sent to instance 0x54a860'
thanks
ipodtouchmaster05 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,605
Threads: 94,084
Posts: 402,783
Top Poster: BrianSlick (7,990)
Welcome to our newest member, champa812
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.