Array of Enums in Swift 3 -


i trying pass 2d array of enums function can see below getting error:

error: cannot convert value of type '[array]' expected argument type '[[piece]]

var won = haswontictactoe(board: board) 

how should done in swift 3?

let board = [[0,0,0], [1,0,1], [1,1,0]]  enum piece {     case red     case blue     case empty }  func haswontictactoe(board: [[piece]]) -> piece {     /*..more code here*/ } 

it's unclear mean [[0,0,0], [1,0,1], [1,1,0]] mean, if mean 0 .red , 1 .blue, meant was:

let board: [[piece]] = [[.red,.red,.red], [.blue,.red,.blue], [.blue,.blue,.red]] 

enum values themselves. not equivalent integers.

keep in mind not "a 2d array." array of arrays. that's different thing. there no rule says each row same length. if want actual matrix, you'd need create data structure; swift doesn't have 1 built in.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

javascript - How to bind ViewModel Store to View? -

javascript - Solution fails to pass one test with large inputs? -