Dmitriy Kalachniuk
Dmitriy Kalachniuk

Reputation: 372

NSarray it is not working

Here is some code

aSong.songDuration = currentElementValue;
NSLog(@"SD = %@",aSong.songDuration);         //   Here aSong.Duration is right
[viewController.songs addObject:aSong];
Music *bSong = [viewController.songs objectAtIndex:1]; // here bSong.Duration is null
NSLog(@"bSong = %@",bSong.songDuration);

I tried different objectAtIndex but all the time the value is null. Is something wrong?

thanks

Upvotes: 0

Views: 69

Answers (1)

Georg Fritzsche
Georg Fritzsche

Reputation: 98984

If you are adding an element to an empty mutable array, it has the index 0:

Music *bSong = [viewController.songs objectAtIndex:0];

Of course that is assuming songs actually is a NSMutableArray (not an NSArray, which is immutable) and that songs exists.

Upvotes: 3

Related Questions