I have been struggling with what should be a fairly simple task.
In viewController.h I have:
@interface MoviesList : NSObject {
}
@property NSString *aTitle;
@property NSDate *aReleaseYear;
@property NSString *aCharacter;
@end
In viewController.m (fetchedData contains a JSON response, movieCount is already determined) I have:
NSMutableArray *moviesArray;
MoviesList *movieDetails = [[MoviesList alloc] init];
int myCount = 0;
while (myCount < movieCount) {
MoviesList *movieDetails = [[MoviesList alloc] init];
// Insert character played into array.
movieDetails.aCharacter = fetchedData[@"cast"][myCount][@"character"];
// Insert movie title and release date into array.
movieDetails.aTitle = fetchedData[@"cast"][myCount][@"title"];
movieDetails.aReleaseYear = fetchedData[@"cast"][myCount][@"release_date"];
[moviesArray addObject:movieDetails];
NSLog(@"Title: %@",movieDetails.aTitle);
NSLog(@"Release date: %@",movieDetails.aReleaseYear);
NSLog(@"Character: %@",movieDetails.aCharacter);
myCount++;
}
NSLog(@"moviesArray: %@",moviesArray);
When I run with breakpoints and hover over 'moviesArray' in the last line above, I can see it gets populated with correct information:
@"58 objects"
[0] = (MoviesList *) 0x7962b650
> NsObject
> _aTitle = blah blah
> _aReleaseYear = blah blah
> _aCharacter = blah blah...
So it appears the array is being populated correctly. The issues now are how to sort this information by release date (I have been combing this forum all day and seen various sorting answers which I have had little success with) and then display the sorted array via NSLOG.
Any help is appreciated, there does seem a wealth of knowledge in this forum and always someone willing to offer assistance. Thank you.