import UIKit
import Foundation
//Structures
struct Person {
var name: String
func sayHello() {
print("Hello, there! My name is \(name)")
}
}
let firstPerson = Person(name: "Kenneth")
print(firstPerson.name)
firstPerson.sayHello()
let person = Person(name: "Zane")
print(person.name)
person.sayHello()
//Instances
//Does not match text example
struct Shirt {
var size: String
var color1: String
}
let myShirt = Shirt(size: "xl", color1: "blue")
//let youShirt = Shirt(size: .m, color: .red)
print(myShirt.size)
struct Color {
var blue: String
var black: UIColor
var green: UIColor
}
struct Direction {
// TODO add stuff
}
struct Car {
var make: String
var year: Int
var color: String
var topSpeed: Int
func startEngine() {
"..."
}
func drive() {}
func park() {}
func steer(direction: Direction) {}
}
let firstCar = Car(make: "Honda", year: 2010, color: "blue", topSpeed: 120)
let secondCar = Car(make: "Ford", year: 2013, color: "black", topSpeed: 125)
firstCar.startEngine()
firstCar.drive()
struct Odometer {
var count: Int = 0
}
let odometer = Odometer(count: 27000)
print(odometer.count)
Leave a Reply