我正在尝试在Xcode 9 beta 3上为Apple提供的Music Kit示例应用程序“添加内容到Apple Music”。但是我有4个这样的错误:三个“模糊地使用'play()'”错误和一个“模糊地使用'pause()'”
如果你已经解决了这个问题,请告诉我如何解决这个问题。
func beginPlayback(itemCollection: MPMediaItemCollection) {
musicPlayerController.setQueue(with: itemCollection)
//Ambiguous use of 'play()’
musicPlayerController.play()
}
func beginPlayback(itemID: String) {
musicPlayerController.setQueue(with: [itemID])
//Ambiguous use of 'play()’
musicPlayerController.play()
}
// MARK: Playback Control Methods
func togglePlayPause() {
if musicPlayerController.playbackState == .playing {
//Ambiguous use of 'pause()’
musicPlayerController.pause()
} else {
//Ambiguous use of 'play()’
musicPlayerController.play()
}
}
答案 0 :(得分:1)
我在Apple的开发论坛中发现了一个类似的问题:
MPMusicPlayerController Swift4 - Ambiguous Use of Play
根据编写修复程序以解决此问题的条目,您需要在MusicPlayerManager.swift中更改此行:
let musicPlayerController = MPMusicPlayerController.systemMusicPlayer
(musicPlayerController
的类型变为MPMusicPlayerController & MPSystemMusicPlayerController
此代码。)
要:
let musicPlayerController: MPMusicPlayerController = MPMusicPlayerController.systemMusicPlayer
(musicPlayerController
明确注释为MPMusicPlayerController
。)
在我看来,这是与SE-0156 Class and Subtype existentials相关的Swift错误,您最好向Apple或swift.org发送错误报告。