I am working on getting a list of songs to sort by artist. I have my code working and can print the songs and artists. Now I want to make it sort and print the list by artist. This is my first attempt at sorting and I know I have to be missing something simple here. I get -- Expected ')'-- and -- use of undeclared identifier 'listSongs' -- This is all in my @implementation file.
Any help is appreciated thank you in advance.
Here is my interface section
@interface Library : NSObject
@property (nonatomic, strong) NSMutableArray *list;
-(id) initList;
-(void) addSong: (Song *) song;
-(void) listSongs;
@end
This is my implementation section
#import "Library.h"
@implementation Library
@synthesize list;
-(id) initList
{
self = [super init];
if (self){
list = [NSMutableArray array];
}
return self;
}
-(id) init
{
return [self initList];
}
-(void) addSong:(Song *)song
{
[list addObject: song];
}
-(void) listSongs
{
NSLog(@"The list of my songs");
NSSortDescriptor *sorter;
sorter = [[[NSSortDescriptor alloc] initWithKey:@"artist" ascending: YES]
NSArray *sortDescriptors = [NSArray arrayWithObjects:sorter]; **// ** Expected ')'**
[listSongs sortUsingDescriptors:sortDescriptors]; //**use of undeclared identifier 'listSongs'
for (Song *song in list)
NSLog(@"%-20s by %s", [song.Title UTF8String], [song.Artist UTF8String]);
}