




























































































Studirajte zahvaljujući brojnim resursima koji su dostupni na Docsity-u
Zaradite bodove pomažući drugim studentima ili ih kupite uz Premium plan
Ova stranica nije vidljiva u pregledu
Ne propustite važne delove!





























































































print("Hello, world!")
On a Mac, download the Playground and double-click the file to open it in Xcode: https://developer.apple.com/go/?id=swift-tour
Simple Values
Create a constant with an explicit type of Float and a value of 4.
Try removing the conversion to String from the last line. What error do you get?
print(teamScore)
Change optionalName optionalName is nil. to nil. What greeting do you get? Add an else clause that sets a different greeting if
print("Everything tastes good in soup.") }
Try removing the default case. What error do you get?
} while m < 100 print(m)
Functions and Closures
Remove the day parameter. Add a parameter to include today’s lunch special in the greeting.
Write a function that calculates the average of its arguments.
return number < 10 } var numbers = [20, 19, 7, 12] hasAnyMatches(list: numbers, condition: lessThanTen)
Add a constant property with let, and add another method that takes an argument.
return "A shape with (numberOfSides) sides." } }
var perimeter: Double { get { return 3.0 * sideLength } set { sideLength = newValue / 3. } }
override func simpleDescription() -> String { return "An equilateral triangle with sides of length (sideLength)." } } var triangle = EquilateralTriangle(sideLength: 3.1, name: "a triangle") print(triangle.perimeter) triangle.perimeter = 9. print(triangle.sideLength)