1
我有一種方法,在創建新匹配(它設置遊戲數據)時調用它,它運行良好,除非有時(隨機),當前參與者在我嘗試保存後變爲零數據。GKTurnBasedMatch currentParticipant在saveCurrrentTurn後變爲零
我已經放在了幾個斷點,並且直到我嘗試保存最初的遊戲數據,currentParticipant
不是零,而是保存後,它有時無:
func enterNewGame(_ match:GKTurnBasedMatch) {
self.match = match
var pArray = [Player]()
let mode: Game.Mode = .quick
self.game = Game(mode: mode, players: pArray)
if match.participants != nil {
for (index, player) in match.participants!.enumerated() {
//populate the pArray with Players, with corresponding initial data.
}
}
// More setup to the Game object here.
//At this point, match.currentParticipant is not nil
let data = NSKeyedArchiver.archivedData(withRootObject: game!)
match.saveCurrentTurn(withMatch: data, completionHandler: {error in
if error != nil {
print(error!.localizedDescription)
return
}
if self.segueToPick != "" {
//At this point, match.currentParticipant is sometimes nil
self.performSegue(withIdentifier: self.segueToPick, sender: self)
}
})
}
任何想法?
謝謝。我會做檢查,如果沒有,我會照你的建議去做。 – coopersita