Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get objects in NSMutableArray

Tags:

objective-c

assume the following:

@interface BOOK : NSObject
{
    @private
    NSString *title;
    NSString *author;
    NSString *ISBN;
}
...
BOOK *booklist = [[[BOOK alloc] init] autorelease];
NSMutableArray *myarray = [NSMutableArray array];
while (true)
{
    booklist.title = @"title";
    booklist.author = @"author";
    booklist.ISBN = @"1234-1";
    [myarray addObject:booklist];
}

my question is how do I retrieve object of BOOK i.e booklist.title, .author, .ISBN at a certain index in myarray.

like image 793
Drew Avatar asked Mar 08 '11 12:03

Drew


1 Answers

with this code? Impossible, because you add the same bookList for the rest of the time (until there is no more memory)

With code without infinite loops you would use

NSInteger index = 0;
Book *aBook = [myArray objectAtIndex:index];
NSString *title = aBook.title;
like image 67
Matthias Bauch Avatar answered Oct 03 '22 01:10

Matthias Bauch