NSMutable array problem.

Discussion in 'Mac Programming' started by jlphoenix, Oct 29, 2008.

  1. jlphoenix macrumors newbie

    Joined:
    Oct 29, 2008
    Location:
    Mexico City
    #1
    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!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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];
     
  3. jlphoenix thread starter macrumors newbie

    Joined:
    Oct 29, 2008
    Location:
    Mexico City
    #3
    Thanks!!

    kainjow thanks por replying!!!:D

    the problem was the initialization of items and NSLog like you said!! I feel so dumb!!
     

Share This Page