Accessing objects using NSPointerArray?

1.6k views Asked by At

I have an NSPointerArray and in one of my methods, I want to access the objects stored in that NSPointerArray (as I have to use one of the object's properties). I don't want to create a new NSArray with the allObjects method as that will be redundant in my program. Right now, I'm doing the following which uses a lot of memory? (Sorry, I'm a noob).

-(void) print
{
    for (int i=0; i<[list count]; i++){
        NSLog(@"%@",[((__bridge Song*)[list pointerAtIndex: i])  title]);
    }
}

Thanks

1

There are 1 answers

3
Alex Cio On

It looks like your problem is already solved. Wanted to mention its easier to loop over your NSPointerArray with a foreach loop. In this case you do it like this:

-(void) print {
    for (Song *s in list){
        NSLog(@"%@", [s title]);
    }
}

This way you can concentrate on the object instead of using the integer of your loop.