TicTacToe icon indicating copy to clipboard operation
TicTacToe copied to clipboard

Getting fatal error: unexpectedly found nil while unwrapping an Optional value

Open riklowe opened this issue 9 years ago • 2 comments

Running the code - first player plays and sends the message to second play

When the second player attempts to play I get following error

              fatal error: unexpectedly found nil while unwrapping an Optional value

The error occurs in the function : func checkColumns(for grid: [[TTTCellState]]) -> Player? on line : owned[user]![j] += 1

I can see on the lines above the one that fails the following

    for player in players {
        owned[player] =  Array(repeating: 0, count: grid[0].count)
    }

and whilst debugging I can see it is only finding one player with an id : 14428D79-F6CB-473D-9536-20A4E85308F6:/:#65D65A

but the user id is C1206121-D4C4-4BA8-A48B-6A012CA510FB:/:#5C9FF5 so I don't think owner[user] is initialised

I am using Xcode 8 / Beta 3

Can you confirm if the code on github still works ?

Any help appreciated

riklowe avatar Jul 28 '16 20:07 riklowe

Hi @riklowe, thanks for the specific & clear issue! I have updated the code on github and am not encountering any errors when testing. Can you run the code and let me know if you are still encountering issues? Also, are you testing on the simulator or on a real device?

Because of a bug in the iOS simulator in which only one UUID is generated for both contacts (instead of a UUID for both contacts), I am not sure whether the current code is completely functional. Because there is only one UUID, the code correctly thinks there is only one player so only one move can be made. I have filed this as a bug report with Apple already and expect it to be fixed in the next update.

amarjayr avatar Jul 29 '16 00:07 amarjayr

Thanks for quick response. Yes I am testing on simulator as I only have 1 device on iOS 10 at the moment - so I guess I need to wait until UUID issue is fixed. Thanks

riklowe avatar Jul 29 '16 06:07 riklowe