ios - Swift 1.2 - Setting element in array of optional types to nil-- not allowed when passed in? -


i've array of boxes types box? allow elements set nil, if there nothing there. want box set spot nil when removed scene.

the following causes no complaints xcode:

override func removefromparent() {         var board = [[box?]](count: 5, repeatedvalue: [box?](count: 9, repeatedvalue: nil))         board[i][j] = nil         super.removefromparent()     } 

and neither making board variable global , using way...

in gamescene.swift:

var board = [[box?]](count: 5, repeatedvalue: [box?](count: 9, repeatedvalue: nil)) 

in box.swift:

override func removefromparent() {         board[i][j] = nil         super.removefromparent()     } 

but trying wont compile (it's no longer overriding because added parameter):

func removefromparent(board: [[box?]]) {         board[i][j] = nil         super.removefromparent()     } 

is there way make work? thanks

your problem board in latter case let , can not changed.

again swift error message misleading here.

if want inout parameter add (inout board:... need pass parameter reference & in call removefromparent(&myboxarray).

ps tried in playground:

var a:[int] = [1, 2, 3] func aa(inout a:[int]) {   a[1] = 9 }  aa(&a) // return [1, 9, 3] 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -