2016-04-07 17 views
0

返回我有這樣的代碼:Objective-C的變量設置取之於方法

-(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

假設urlOfCurrentlyPlayingInPlayer在相同的類被聲明:

NSURL *currentSong = [self urlOfCurrentlyPlayingInPlayer:_audioPlayer1]; 

如果這是一些其他類的實例方法,它將是

NSURL *currentSong = [myInstanceOfSomeOtherClass urlOfCurrentlyPlayingInPlayer:_audioPlayer1];