swiftlyfox/SwiftyFox.playground/Contents.swift

39 lines
841 B
Swift

import Cocoa
func greet(_ person: String, on day: String) -> String {
return "Hello \(person), today is \(day)."
}
// "Hello Tony Bark, today is Tuesday."
greet("Tony Bark", on: "Tuesday")
func calcStats(scores: [Int]) -> (min: Int, max: Int, sum: Int) {
var min = scores[0]
var max = scores[0]
var sum = 0
for score in scores {
if score > max {
max = score
} else if score < min {
min = score
}
sum += score
}
return (min, max, sum)
}
let stats = calcStats(scores: [5, 3, 100, 3, 9])
let sum = stats.sum // 120
class Shape {
var numberOfSides = 0
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."
}
}
var shape = Shape()
shape.numberOfSides = 7
var shapeDesc = shape.simpleDescription()