Search code examples
iosobjective-cuitableviewkeyfeed

How to check if a key has no value


I have two feeds and i want with the content of them to populate a table view, but when i want to display the images the key are diffrents so in cellForRowAtIndexPath i have:

 if ([[stories objectAtIndex:storyIndex] objectForKey:@"url"] ==nil) {
        [cell.imag setImageWithURL:[NSURL URLWithString:[[stories objectAtIndex:storyIndex] objectForKey:@"_text"]] placeholderImage:[UIImage imageNamed:@"Alb.png"]];
    }

    else
        [cell.imag setImageWithURL:[NSURL URLWithString:[[stories objectAtIndex:storyIndex] objectForKey:@"url"]] placeholderImage:[UIImage imageNamed:@"Alb.png"]];

but it's not working.


Solution

  • use this code

    if ([dictionary objectForKey:key]) {
    // contains object
    }
    else
    {
    //no object
    }