我有两个课程,歌曲课程和播放列表课程。
这是 Song.h:
#import <Foundation/Foundation.h>
@interface Song : NSObject
@property (nonatomic, copy) NSString *artist, *title, *album, *time;
-(void) setSong:(NSString *)theSongName andArtist:(NSString *)theArtist andAlbum:(NSString *)theAlbum andPlayingTime:(NSString *)theTime;
@end
宋.m
@implementation Song
@synthesize title, album, artist, time;
-(void) setSong:(NSString *)theSongName andArtist:(NSString *)theArtist andAlbum:(NSString *)theAlbum andPlayingTime:(NSString *)theTime{
self.title = theSongName;
self.artist = theArtist;
self.album = theAlbum;
self.time = theTime;
}
@end
播放列表.h
@interface PlayList : NSObject
@property (nonatomic, copy) NSString *playListName;
@property (nonatomic, copy) NSMutableArray *songsCollection;
-(void) addSongToPlayList:(Song *) someSong;
-(void) removeSongFromPlayList:(Song *) theSong;
-(void) print;
@end
播放列表.m:
@implementation PlayList
@synthesize songsCollection, playListName;
-(void) addSongToPlayList:(Song *) someSong{
[songsCollection addObject:someSong];
}
-(void) removeSongFromPlayList:(Song *)theSong{
[songsCollection removeObjectIdenticalTo:theSong];
}
-(void) print{
NSLog(@"================= Playlist Name: %@ =============", playListName);
for (Song *nextSong in songsCollection){
NSLog(@"Artist Song Album Time");
NSLog(@"------ ---- ----- ----");
NSLog(@"%s %s %s %s ", [nextSong.artist UTF8String], [nextSong.title UTF8String], [nextSong.album UTF8String], [nextSong.time UTF8String]);
NSLog(@"=================================================");
}
}
@end
该print
方法给我带来了问题,它只打印这一行:
NSLog(@"================= Playlist Name: %@ =============", playListName);
主文件
#import <Foundation/Foundation.h>
#import "Song.h"
#import "PlayList.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Song *song1 = [[Song alloc] init];
[song1 setSong:@"Flying away" andArtist:@"Madona" andAlbum:@"Love collection" andPlayingTime:@"3:52"];
PlayList *playList1 = [[PlayList alloc] init];
[playList1 setPlayListName:@"Cool Soongs to listen"];
[playList1 addSongToPlayList:song1];
[playList1 print];
}
return 0;
}