Wednesday, December 9, 2015

Type Annotations

You can provide a type annotation when you declare a constant, to be clear about the kind of values the constant can store


import Cocoa



let constB:Float = 3.14159
let constc:Int = 3.14159// double is not allowed here 

println(constB)

println(constc)

produces following error 
main.swift:6:18: error: 'Double' is not convertible to 'Int'
let constc:Int = 3.14159

No comments:

Post a Comment