Created
September 9, 2017 20:11
-
-
Save freewayz/d8b435dfaee7c4dbe5cbec07b63ae679 to your computer and use it in GitHub Desktop.
My first two hours on swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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