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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With