Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Determine Swift Inferred Type in Xcode 6

Tags:

xcode

swift

Say I have something like

let a = <some-complicated-expression>

Is there any way within Xcode to check which type the compiler has inferred for a?

EDIT: \

For example, in the Eclipse Scala IDE, by hovering over the variable name the editor would show the inferred type

like image 487
Eduardo Avatar asked Jun 05 '14 03:06

Eduardo


People also ask

What is inferred type in Swift?

Swift uses type inference extensively, allowing you to omit the type or part of the type of many variables and expressions in your code. For example, instead of writing var x: Int = 0 , you can write var x = 0 , omitting the type completely—the compiler correctly infers that x names a value of type Int .

What is () type in Swift?

Yes, it's the empty tuple, aka Void . The standard Void type is defined as: typealias Void = () The return type of functions that don't explicitly specify a return type; an empty tuple (i.e., () ).

How do you print a variable in Swift?

In Swift, you can print a variable or a constant to the screen using the print() function. Let's see that in action by creating a playground file, as you learned in the last lesson. After creating your new playground in Xcode, start by declaring three strings representing your favorite word, color, and musician.


1 Answers

Yes. Alt click the variable and you'll get a pop over with the type.

enter image description here

like image 124
Dave Wood Avatar answered Sep 21 '22 22:09

Dave Wood