问题描述
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file HATurnBasedMatchHelper.swift,line 244
2021-01-25 20:36:22.317564-0500 QuizApp[14288:4507393] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file HATurnBasedMatchHelper.swift,line 244
func player(_ player: GKPlayer,receivedTurnEventFor match: GKTurnBasedMatch,didBecomeActive: Bool) {
// Crash on Line 244
// state of self when using notification
/*
self QuizApp.HATurnBasedMatchHelper 0x0000000281a4c310
ObjectiveC.NSObject NSObject
reachability QuizApp.Reachability? 0x0000000281a4c7e0
savetoLoseList Bool? false some
isMultiplayerGame Bool? false some
currentMatch GKTurnBasedMatch? 0x0000000283e29530
selectedCategory QuizApp.HACategory? nil none
delegate QuizApp.HATurnbasedMatchHelperDelegate? nil none
presentingViewController UIViewController? nil none
myWins Int64 1
pendingWins Int64 0
takeAnotherChallenge Bool? false some
*/
/* I added the if condition to check if the VC is nil */
if self.presentingViewController != nil {
self.presentingViewController.dismiss(animated: true,completion: nil)
}
self.currentMatch = match
let firstParticipant = match.participants[0]
if firstParticipant.lastTurnDate == nil
{
delegate.enterNewGame(match: match)
}
else{
var statusstring : String? = nil
var thisParticipant : GKTurnBasedParticipant? = nil
var otherParticipant : GKTurnBasedParticipant? = nil
for participant in match.participants
{
if participant.player?.playerID == GKLocalPlayer.local.playerID
{
thisParticipant = participant
}
else{
otherParticipant = participant
}
}
if thisParticipant?.matchOutcome == .quit {
statusstring = "You have Quit this match"
}
else if otherParticipant?.matchOutcome == .quit
{
statusstring = "Opponent has Quit this match"
}
else if otherParticipant?.status == .declined
{
statusstring = "Opponent has Declined your challenge"
}
if statusstring == nil{
if match.currentParticipant?.player?.playerID == GKLocalPlayer.local.playerID
{
// crash here
// delegat is nil. I posted all values of self above
delegate.takeTurn(match: match)
}
else{
delegate.layout(match: match)
}
}
else{
let alertController = UIAlertController(title: "Match status\n",message:statusstring,preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok",style: .default) { (action) in
}
alertController.addAction(okAction)
self.presentingViewController.present(alertController,animated: true,completion: nil)
}
}
}
我不确定我在这里做错了什么。
确切的错误是
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)