I`m making an exercise, i have 2 classes Songs and Playlist, in the program i can put songs in playlist and everything is working fine, but i need to make a master playlist with all the songs that are in all the normal playlist and there is the problem.
Here is the code
//
// main.m
// MyItunes
//
// Created by Rodrigo López on 6/29/12.
// Copyright (c) 2012 ITQ. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Songs.h"
#import "PlayList.h"
int main (int argc, const char * argv[])
{
@autoreleasepool {
Songs *mySong1 = [Songs new];
Songs *mySong2 = [Songs new];
Songs *mySong3 = [Songs new];
PlayList *myPlayList1=[[PlayList alloc]initWithName:@"First"];
PlayList *myPlayList2=[[PlayList alloc]initWithName:@"Second"];
[mySong1 setTitle:@"Back In Black" setArtist:@"AC/DC" setAlbum:@"Back In Black" setPlayt:@"4:16"];
[mySong2 setTitle:@"Medicate" setArtist:@"AFI" setAlbum:@"Crash Love" setPlayt:@"4:21"];
[mySong3 setTitle:@"Rucci" setArtist:@"Austin TV" setAlbum:@"La ultima noche" setPlayt:@"4:39"];
[myPlayList1 addSong:mySong1];
[myPlayList1 addSong:mySong2];
[myPlayList2 addSong:mySong3];
[myPlayList1 showPlayList];
[myPlayList2 showPlayList];
[myPlayList1 showPlayList];
[myPlayList1 showAllSongs];
}
return 0;
}
//
// PlayList.m
// MyItunes
//
// Created by Rodrigo López on 6/29/12.
// Copyright (c) 2012 ITQ. All rights reserved.
//
#import "PlayList.h"
@implementation PlayList
@synthesize playListarray,playListName;
-(id) initWithName: (NSString *) name
{
if(self)
{
playListName = [NSString stringWithString: name];
playListarray = [NSMutableArray array];
playlistMaster=[NSMutableArray array ];
}
return self;
}
-(void) addSong: (Songs *) theSong
{
[playListarray addObject:theSong];
[playlistMaster addObject:theSong];
}
-(void) showPlayList
{
NSLog(@"Play List: %@", self.playListName);
for(Songs *theSong in playListarray)
{
NSLog(@"%@", theSong.title);
}
}
-(void) showAllSongs
{
NSLog(@"Play List: Master");
for(Songs *theSong in playlistMaster)
{
NSLog(@"%@", theSong.title);
}
}
-(NSUInteger) entries
{
return [playListarray count];
}
-(void) remove: (Songs *) theSong
{
[playListarray removeObjectIdenticalTo:theSong];
}
@end
The problem is with the NSMutable array, i want to declare the array globally, but i dont know how to do it, here is the output of this program:
2012-06-29 19:24:06.061 MyItunes[17184:707] Play List: First
2012-06-29 19:24:06.080 MyItunes[17184:707] Back In Black
2012-06-29 19:24:06.083 MyItunes[17184:707] Medicate
2012-06-29 19:24:06.084 MyItunes[17184:707] Play List: Second
2012-06-29 19:24:06.085 MyItunes[17184:707] Rucci
2012-06-29 19:24:06.089 MyItunes[17184:707] Play List: First
2012-06-29 19:24:06.090 MyItunes[17184:707] Back In Black
2012-06-29 19:24:06.091 MyItunes[17184:707] Medicate
2012-06-29 19:24:06.091 MyItunes[17184:707] Play List: Master
2012-06-29 19:24:06.092 MyItunes[17184:707] Back In Black
2012-06-29 19:24:06.093 MyItunes[17184:707] Medicate
So in play list master, its missing Rucci song, hope you can help me, thank you very much, i appreciate it