NSMutableDictionary Remains Null After Entry Added

Discussion in 'iOS Programming' started by zachsilvey, Dec 29, 2010.

  1. zachsilvey macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
    #1
    Code:
    NSLog(@"%@", book);
    NSLog(@"%@", [completeBooksDictionary objectForKey:book]);
    [selectedBooksDictionary setObject:[completeBooksDictionary objectForKey:book] forKey:book];
    So the first two line demonstrate that those messages do in fact return objects (the first a string constant and the second a dictionary).

    Why is that when I use the third line to add the key-value pair it doesn't work?

    If I add the entry then use

    Code:
    NSLog(@"%@", selectedBooksDictionary);
    I get Null
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    Did you ever do the alloc and init on the

    selectedBooksDictionary

    ?
     
  3. zachsilvey thread starter macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    That doesn't necessarily allocate it, though.
     
  5. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #5
    At some point you have to call something like:

    Code:
    NSMutableDictionary *selectedBooksDictionary = [[NSMutableDictionary alloc] init];
    
    Or something like that.
     

Share This Page