Objective-C 将变量设置为方法返回的值
Objective-C set variable to what is returned from method
我有这个代码:
-(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];
错误消息是 "Expected expression" NSURL 的 N 带有红色下划线
抱歉这个菜鸟问题
假设在同一个 class 中声明了 urlOfCurrentlyPlayingInPlayer
:
NSURL *currentSong = [self urlOfCurrentlyPlayingInPlayer:_audioPlayer1];
如果它是其他一些 class 的实例方法,它将是
NSURL *currentSong = [myInstanceOfSomeOtherClass urlOfCurrentlyPlayingInPlayer:_audioPlayer1];
我有这个代码:
-(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];
错误消息是 "Expected expression" NSURL 的 N 带有红色下划线
抱歉这个菜鸟问题
假设在同一个 class 中声明了 urlOfCurrentlyPlayingInPlayer
:
NSURL *currentSong = [self urlOfCurrentlyPlayingInPlayer:_audioPlayer1];
如果它是其他一些 class 的实例方法,它将是
NSURL *currentSong = [myInstanceOfSomeOtherClass urlOfCurrentlyPlayingInPlayer:_audioPlayer1];