Objective-C将变量设置为从方法返回的内容

时间:2016-04-07 23:56:11

标签: objective-c avplayer nsurl

我有这段代码:

-(NSURL *)urlOfCurrentlyPlayingInPlayer:(AVPlayer *)player{
// get current asset
AVAsset *currentPlayerAsset = player.currentItem.asset;

// make sure the current asset is an AVURLAsset
if (![currentPlayerAsset isKindOfClass:AVURLAsset.class]) return nil;

// return the NSURL
return [(AVURLAsset *)currentPlayerAsset URL];

}

为什么我不能这样做?

NSURL *currentSong=[urlOfCurrentlyPlayingInPlayer:_audioPlayer1];

错误消息是“预期表达式”,NSURL的N用红色下划线标出

抱歉noob问题

1 个答案:

答案 0 :(得分:1)

假设urlOfCurrentlyPlayingInPlayer在同一个类中声明:

NSURL *currentSong = [self urlOfCurrentlyPlayingInPlayer:_audioPlayer1];

如果它是某个其他类的实例方法,那么它将是

NSURL *currentSong = [myInstanceOfSomeOtherClass urlOfCurrentlyPlayingInPlayer:_audioPlayer1];