A Swift Tour Flashcards
Write Hello, World!
print(“Hello, World!”)
Write the variable named myVariable and make it = to 42
var myVariable = 42
Write a constant variable named myConstant and make it = to 50
let myConstant = 50
Write an implicit constant integer named implicitInteger and make it = 70
let implicitInteger = 70
Write an implicit constant double named implicitDouble and make it = 70.0
Let implicitDouble = 70.0
Write an explicit constant double named explicitDouble and make it = 70
Let explicitDouble:Double = 70
Write and explicit float constant named myFloat = 4.0
Let myFloat: Float = 4.0
let label = “The width is “
let width = 94
Write an implicit constant string named widthLabel = “The width is 94” using the constants label and width
let widthLable = label + String(width)
let apples = 3
let oranges = 5
Write and implicit string constant named appleSummary and use the parentheses to show “I have 3 apples” using the variable apples
let appleSummary = “I have (apples) apples”
Create a variable array called shoppingList = “catfish”, “water”, “tulips”, “blue paint”
var shoppingList = [“catfish”, “water”, “tulips”, “blue paint”]
make the second item of a declared variable array called shoppingList = “bottle of water”
shoppingList[1] = “bottle of water”
var occupations = [“Malcolm”: “Captain”,”Kaylee”: “Mechanic”,]
Add a new pair value to the occupations dictionary: Jaine = Public Relations
occupations[“Jaine”] = “Public Relations”
Create an empty dictionary named emptyDictionary using the initializer syntax
let emptyDictionary = String: Float
If type information can be inferred, write an empty array named shoppingList
var shoppingList = []