Drew Drew - 1 month ago 19
Objective-C Question

get objects in NSMutableArray

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.

Answer

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;