Swift Types inside Parentheses -


i playing around swift today, , strange types started crop up:

let flip = int(random()%2)  //or arc4random(), or rand(); whatever prefer 

if type flip xcode 6 (beta 2), auto-complete pops up, , says flip of type (int) instead of int.

this can changed:

let flip : int = int(random()%2) let flop = random()%2 

now flip , flop of type int instead of (int)

playing around more, these "parentheses types" predictable , can cause them adding parentheses in part of variable's assignment.

let g = (5)      //becomes type (int) 

you can cause additional parentheses in type!

let h = ((5))    //becomes type ((int)) let k = (((5)))  //becomes type (((int))) //etc. 

so, question is: difference between these parentheses types such (int) , type int?

partly it's parentheses meaningful.

let g = (5) 

...means g tuple consisting of 1 int, symbolized (int). it's one-element version of (5,6), symbolized (int,int).

in general need quite careful parentheses in swift; can't used old place. have meaning.

however, it's partly code completion mechanism buggy. if have reproducible case, file report apple.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -