Thursday, February 16, 2017

Play Swift in playground

Swift insight


Basic Data Type syntax:

print("Hello World!")
let t = 10
print ("value " ,t, "\n\n", 20, t*2 )
//t=20


var value = 100

if value > t && value < 200 {
  print("value is good!!!!!")
  value -= 10
  print("now value is  ",  value)
}

var intValue : Int = 200

print(intValue , "is Integer")

// Declaring variables of a certain type
var myBool:Bool = false

var myDouble:Double = 23.45

var myLongInt:Int = 235412452354356


var myvalue:Int = 5/2

//var a1:Double  // error: repl.swift:29:1: error: variables currently must have an initial value when entered at the top level of the REPL var a1:Double

//var a1:Double=nil  
/*error: repl.swift:31:15: error: nil cannot initialize specified type 'Double'
var a1:Double=nil
              ^

repl.swift:31:8: note: add '?' to form the optional type 'Double?'
var a1:Double=nil*/


let a1:Double? = nil 

//myBool+myDouble
/* error: repl.swift:42:7: error: binary operator '+' cannot be applied to operands of type 'Bool' and 'Double'
myBool+myDouble
~~~~~~^~~~~~~~~

repl.swift:42:7: note: expected an argument list of type '(Double, Double)'
myBool+myDouble */

No comments:

Post a Comment