Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jlphoenix

macrumors newbie
Original poster
Oct 29, 2008
2
0
Mexico City
Hi!, please... please... anyone help me, I'm trying to solve the challenge from chapter 6 of Aaron's Book...

I have to make a "to do" list... and I wrote this method:

Code:
-(IBAction) add:(id)sender
{
	
	NSString *str= [[NSString alloc] initWithString:[newItemField stringValue]];
	
	[items addObject:str];
	
	NSLog(@"count: %@",[items count]);
}

items is a NSMutableArray, and newItemField is a NSTextField...

The problem is that the console says that items count is NULL...!!! I don't know why I can't add object to the Mutable Array!:(

Please someone help me, i know that the solution is silly but I'm desperate, and can't finish the book if I dont solve this!
Thank you!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
1. To print an integer use %d not %@. %@ is for objects.
2. Make sure you initialized items correctly. If you're unsure post your code.
3. There is no need (in this instance) to create a new string object. You can just declare it like so:
Code:
NSString *str = [newItemField stringValue];
 

jlphoenix

macrumors newbie
Original poster
Oct 29, 2008
2
0
Mexico City
Thanks!!

kainjow thanks por replying!!!:D

the problem was the initialization of items and NSLog like you said!! I feel so dumb!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.