我正在尝试在Xcode中创建一个新的Objective-C类,并且在.m文件中遇到了上述几个错误.
#import "Query.h"
@implementation Query {
MPMediaQuery *query = [[MPMediaQuery alloc] init]; //create new query
[[query addFilterPredicate: [MPMediaPropertyPredicate
predicateWithValue: @"Vampire Weekend"
forProperty: MPMediaItemPropertyArtist]]; //filter out artists except for Vampire Weekend
// Sets the grouping type for the media query
[query setGroupingType: MPMediaGroupingAlbum]; //sort by album
NSArray *albums = [query collections];
for (MPMediaItemCollection *album in albums) {
MPMediaItem *representativeItem = [album representativeItem];
NSString *artistName =
[representativeItem valueForProperty: MPMediaItemPropertyArtist];
NSString *albumName =
[representativeItem valueForProperty: MPMediaItemPropertyAlbumTitle];
NSLog (@"%@ by %@", albumName, artistName);
NSArray *songs = [album items];
for (MPMediaItem *song in songs) {
NSString *playCount = [song valueForProperty:MPMediaItemPropertyPlayCount];
NSString *lastPlayed = [song valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *songTitle =
[song valueForProperty: MPMediaItemPropertyTitle];
//NSString *info = [[NSString alloc] initWithFormat: @"%@ has been played %@ times.\n Last played %@.", songTitle, playCount, lastPlayed];
NSLog(@"\n%@ has been played %@ times.\n Last played %@.", songTitle, playCount, lastPlayed);
}
}
// Override point for customization after application launch.
[query release];
}
@end
Run Code Online (Sandbox Code Playgroud)
Xcode吓坏了,并在我定义一个对象的行上给出错误,或者尝试使用查询(因为它是未定义的).
我的头文件如下(不完整,但我停下来处理这个):
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface Query : NSObject {
MPMediaQuery *query;
}
@property (nonatomic, retain) MPMediaQuery *query;
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8939 次 |
| 最近记录: |