Skip to content

Instantly share code, notes, and snippets.

@freewayz
Created September 9, 2017 20:11
Show Gist options
  • Save freewayz/d8b435dfaee7c4dbe5cbec07b63ae679 to your computer and use it in GitHub Desktop.
Save freewayz/d8b435dfaee7c4dbe5cbec07b63ae679 to your computer and use it in GitHub Desktop.
My first two hours on swift
var shouldStoreDouble: Double = 200.0 // we restrict this by adding an annotation
print("Double annotation ", shouldStoreDouble);
// let see when we say our computer should create
// a memory space for string but we try to store an integer
var onlyStringPlease: String = "John"
print("String annotation ", onlyStringPlease)
// changing the next line throws error
// onlyStringPlease = 10
// we should get an error
// [cannot convert value of type 'Int' to specified type 'String']
// this can also be done on collections
var userSelectedItem = ["rice", "beans"]
print(userSelectedItem)
// In general swift give us this two things
// Type Inference [ var myInt = 10]
// Type Safety [ let ourDouble: Double = 20.0 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment