我試圖做的方法斯威夫特重載用下面的代碼:「不正確的參數標籤」當斯威夫特
struct Game {
private let players: [UserProfile] //set in init()
private var scores: [Int] = []
mutating func setScore(_ score: Int, playerIndex: Int) {
//... stuff happening ...
self.scores[playerIndex] = score
}
func setScore(_ score: Int, player: UserProfile) {
guard let playerIndex = self.players.index(of: player) else {
return
}
self.setScore(score, playerIndex: playerIndex)
}
}
我上self.setScore
線得到一個錯誤:
Incorrect argument labels in call (have _:playerIndex:, expected _:player:)
我一直在看這段代碼一段時間,但不知道爲什麼這不起作用。任何提示?
你試圖調用非'mutating'方法裏面'mutating'方法 - 類似於Q&A:http://stackoverflow.com/ q/40811214/2976878 – Hamish
你是對的!謝謝。如果你從中得出答案,我會接受。 – BlackWolf
這樣的錯誤信息是一個紅色鯡魚的情況應該是[作爲編譯器錯誤提交給Swift開源項目](http://bugs.swift.org)。 – rickster