簡體   English   中英

在saveCurrrentTurn之后,GKTurnBasedMatch currentParticipant變為零

[英]GKTurnBasedMatch currentParticipant becomes nil after 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)
        }

    })


}

有任何想法嗎?

嘗試重新加載保存程序完成處理程序頂部的匹配對象。 我知道這聽起來很蹩腳。 由於它是隨機發生的,我懷疑(又一個) GKTurnBasedMatch錯誤。

但是,我在Apple的文檔中某處提到有關匹配對象變得陳舊(和/或從查詢所有匹配列表中接收不可靠的匹配對象,直到您實際為每個找到的匹配調用loadMatchWithID ),所以我最終變得非常自由我使用的loadMatchWithID作為使用的必要成本GKTurnBasedMatch

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM