Skip to content

Instantly share code, notes, and snippets.

@anoop4real
Last active August 23, 2018 06:29
Show Gist options
  • Select an option

  • Save anoop4real/af8cc426534fbac96aa9c7b00dea0878 to your computer and use it in GitHub Desktop.

Select an option

Save anoop4real/af8cc426534fbac96aa9c7b00dea0878 to your computer and use it in GitHub Desktop.
Swift reference

var is used for variable in Kotlin also

var variables = " I am a variable"
variables = "I can be re-assigned"

let used in Swift val is used for constant in Kotlin

let constant  = " I am a constant"
//constant = " I cannot be re-assigned" //Error

Type Inference

var text = "hello" // Inferred as String
var number = 45.0  // Inferred as Double
var numberFloat:Float = 45.0  // Inferred as Float

// String interpolation to construct texts
print ("Value of variables is \(variables)")

Multi Line String

let multilineString = """
Hello I am a
multiline string
"""
print(multilineString)

Groups Multiple Values into a single compound values.Tuples can hold different data types also

let error = ( 500, "Internal Server Error") // tuple of type (Int, String)

// Decompose a tuple
// In Kotlin, we can use Pairs or Triples for this
let (code, errorMessage) = error
print(code)
print(errorMessage)

// Used in a situation where value can be absent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment