ios - Initialising an array of two tuples fails -


i have simple function returns array of tuples

func findnodeneighbors(node: node) -> [(node: node, distance: double)] {     var neighbors = [(node: node, distance: double)]()     var nodelinks = linkswith(node)     link in nodelinks {         neighbors.append((node: link.othernodelinkedwith(node), distance: link.length))     }     return neighbors } 

but turns out error invalid use of () call clue of non-function type on first line of function body.

if instead declare type neighbors explicitly, fine.

var neighbors: [(node: node, distance: double)] = [] 

how come?

i've read preferred declare arrays initialising them , allowing implicit type inference.

pretty bug in swift's parser, [type] sugar in combination named tuples.

var neighbors = array<(node: node, distance: double)>() (which should identical [(node: node, distance: double)]()) works fine.

edit: looks dictionary equivalent has same problem

works fine:

var d = dictionary<int,(x: int, y: int)>() 

busted:

var d = [int:(x: int, y: int)]() 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -