I want to add in an array 3 different arrays .. i really don't know how it works .. i've tried several ways but none did work. Can anyone help me please ?
#import "CoursesModel.h"
@implementation CoursesModel
@synthesize courses=_courses,coursesA=_coursesA,coursesB=_coursesB,coursesC=_coursesC;
-(NSArray *) coursesA
{
if(!_coursesA)
{
_coursesA = [[NSArray alloc]initWithObjects:@"A 1",A 2",A 3", nil];
}
return _coursesA;
}
-(NSArray *) coursesB
{
if(!_coursesB)
{
_coursesB = [[NSArray alloc]initWithObjects:@"B 1",@"B 2",@"B 3", nil];
}
return _coursesB;
}
-(NSArray *) coursesC
{
if(!_coursesC)
{
_coursesC = [[NSArray alloc]initWithObjects:@"C 1",@"C 2",@"C 3", nil];
}
return _coursesC;
}
-(NSMutableArray *) courses
{
if(!_courses)
{
_courses = [[NSMutableArray alloc]initWithCapacity:3];
[_courses addObject:_coursesA];
[_courses addObject:_coursesB];
[_courses addObject:_coursesC];
}
return _courses;
}
@end
This is the code i tried using but when i tried using the values from the array courses it did not work properly. For example, i want to call the first row from the array "coursesA" if i enter "self.courses[0][0]" it gives me this error
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
Thanks for helping
self.courses[0][0]line that gives you the error?