I have two custom objects: Movie and MovieTheater. In MovieTheater I have an NSMutableArray that I'm required to use to add movies. This is my code:
// theater 1
MovieTheater* tempTh1 = [[MovieTheater alloc]init];
Movie* tempMv1 = [[Movie alloc]init];
if (tempTh1 != nil) {
// set up a theather
tempTh1.theaterName = @"Regal";
tempTh1.theaterLocation = @"35335 Riverside,CA 92506";
tempTh1.theaterImage = [UIImage imageNamed:@"theatremain.ashx.jpg"];
// set up movie 1 ------------------------------------------------------------------
if (tempMv1 != nil) {
tempMv1.movieName = @"The Zero Theorem";
tempMv1.movieTime = @"SAT 18:30";
tempMv1.movieImage = [UIImage imageNamed:@"zerotheorem.jpg"];
tempMv1.movieTrailer = [NSURL URLWithString:@"http://youtu.be/XpsJPOMfGSo"];
// add movie to theater array
[tempTh1.theaterMovies insertObject:tempMv1 atIndex:0];
}
// set up movie 2 ------------------------------------------------------------------
Movie* tempMv2 = [[Movie alloc]init];
if (tempMv2 != nil) {
tempMv2.movieName = @"Welcome to the Jungle";
tempMv2.movieTime = @"TH 16:30";
tempMv2.movieImage = [UIImage imageNamed:@"welcometothejungle.jpg"];
tempMv2.movieTrailer = [NSURL URLWithString:@"http://youtu.be/kRzSImxqQtA"];
}
// add movie to theater array
[tempTh1.theaterMovies insertObject:tempMv2 atIndex:1];
// set up movie 3 ------------------------------------------------------------------
Movie* tempMv3 = [[Movie alloc]init];
if (tempMv3 != nil) {
tempMv3.movieName = @"The Bag Man";
tempMv3.movieTime = @"TUE 15:30";
tempMv3.movieImage = [UIImage imageNamed:@"bagman.jpg"];
tempMv3.movieTrailer = [NSURL URLWithString:@"http://youtu.be/mKBLfwVEKP8"];
}
// add movie to theater array
[tempTh1.theaterMovies insertObject:tempMv3 atIndex:2];
// set up movie 4 ------------------------------------------------------------------
Movie* tempMv4 = [[Movie alloc]init];
if (tempMv4 != nil) {
tempMv4.movieName = @"Better Living Through Chemistry";
tempMv4.movieTime = @"MO 16:45";
tempMv4.movieImage = [UIImage imageNamed:@"betterlivingthroughchemistry.jpg"];
tempMv4.movieTrailer = [NSURL URLWithString:@"http://youtu.be/qxHPqHIl11w"];
}
// add movie to theater array
[tempTh1.theaterMovies insertObject:tempMv4 atIndex:3];
// set up movie 5 ------------------------------------------------------------------
Movie* tempMv5 = [[Movie alloc]init];
if (tempMv5 != nil) {
tempMv5.movieName = @"Blood Ties";
tempMv5.movieTime = @"FR 19:00";
tempMv5.movieImage = [UIImage imageNamed:@"bloodties.jpg"];
tempMv5.movieTrailer = [NSURL URLWithString:@"http://youtu.be/DI86othXjho"];
}
// add movie to theater array
[tempTh1.theaterMovies insertObject:tempMv5 atIndex:4];
// add the theater to the global array
[cinemas insertObject:tempTh1 atIndex:0];
NSLog(@"%@", tempTh1.theaterMovies);
}
The problem I have is that [tempTh1.theaterMovies insertObject:tempMv1 atIndex:0]; does not add anything. The NSLog shows the array theaterMovies nil. What am I doing wrong?