NSArray * ComicArray = [TCSDataBase fetchManagedObjectsForEntity:@"ComicDB" withPredicate:nil];
[ComicArray retain];
arrayOfComics = [NSMutableArray arrayWithArray:ComicArray];
[[arrayOfComics valueForKey:@"Name"] sortUsingSelector:@selector(caseInsensitiveCompare:)];
[ComicArray release];
Why are all the object in the arrayOfComics out of scope?
EDIT: I tried doing this:
NSArray * ComicArray = [TCSDataBase fetchManagedObjectsForEntity:@"ComicDB" withPredicate:predicate];
arrayOfComics =[[NSMutableArray alloc] init];
for (int i = 0; i < [ComicArray count]; i++) {
[arrayOfComics addObject:[ComicArray objectAtIndex:i]];
}
[[arrayOfComics valueForKey:@"Name"] sortUsingSelector:@selector(caseInsensitiveCompare:)];
All the objects in arrayOfComics are still out of scope….
EDIT: This works, the objects in arrayOfComicsTest are NOT “out of scope”. I am not sure why this works yet when i do arrayOfComics they are out of scope. arrayOfComics is a class variable NSMutableArray * arrayOfComics in the .h. It is not used anywhere until this point.
NSMutableArray * arrayOfComicsTest = [NSMutableArray arrayWithArray:ComicArray];
At the time I was having a bunch of problems because I did not fully understand the difference between mutable and non mutable arrays, as well as the various return values from array operations.
I eventually fixed this by making a bunch of changes.
Thanks to everyone that provided help.