【发布时间】:2011-09-03 01:44:51
【问题描述】:
我了解到此错误来自内存管理问题,例如向已释放的对象发送消息。在第二个“for”部分的第一行中,我在评论“输出有关 'info' 数组中歌曲的信息”之后立即收到错误消息。 info 数组是否没有存储我在第一个“for”部分中提供的对象?
还有其他想法吗?
MPMediaQuery *query = [[MPMediaQuery alloc] init]; //query iPod library
NSMutableArray *info; //create array to hold songs that fit
NSArray *allSongs = [query collections];
//only add those songs which have not
//been played since last login
for (MPMediaItem *recent in allSongs) {
NSDate *lastPlayed = [recent valueForProperty:MPMediaItemPropertyLastPlayedDate];
BOOL uploadInfo = [[PlayedSinceLastLogin alloc] initWithLastPlayedDateOfSong:lastPlayed] ;
if (uploadInfo == YES) {
[info addObject:recent];
}
}
//output information about songs
//in the 'info' array
for (MPMediaItem *played in info) {
NSString *playCount = [played valueForProperty:MPMediaItemPropertyPlayCount];
NSString *lastPlayed = [played valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *songTitle =
[played valueForProperty: MPMediaItemPropertyTitle];
NSString *artistName =
[played valueForProperty: MPMediaItemPropertyArtist];
NSString *albumName =
[played valueForProperty: MPMediaItemPropertyAlbumTitle];
NSLog (@"\n %@ by %@, from album %@, played since last login.\nLast Played:%@.\nTotal Play Count: %@.", songTitle, artistName, albumName, lastPlayed,playCount);
}
【问题讨论】:
标签: iphone objective-c xcode memory-management