I narrowed down my problem to not allocating memory properly. I have a NSMutableArray called subjects as a member of a Category. When I populate the category with the array of subjects it doesn’t store.
I am not sure how and where to allocate the memory for subjects, which is what I believe my problem is.
Here is the snippet:
Category *cat = [[Category alloc] init];
cat.category_title = [result_categories stringForColumn:@"CATEGORY"];
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
for (Subject *sb in appDelegate.subjects){
if([cat.category_title isEqualToString:sb.category_title]){
[cat.subjects addObject:sb];
NSLog(@"Adding subject: %@ cat.subjects.count=%i", sb.title, cat.subjects.count);
}
}
(The above log does print cat.subject names but it doesn’t print the subjects.count)
Have you allocate memory to
cat.subjectslikeor
in your
Categoryclass ? if not then do it. This might be the one of the problem.Update
first of all change your code from
Category *cat = [Category alloc];toCategory *cat = [[Category alloc] init];and change your init as