• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

KennethJackson.Tech

Multimedia Production in Amarillo, Texas

  • Home
  • IT Services
    • Web
  • Music
    • Audio
    • Woodshed
  • Video
  • News
  • About
  • Contact
You are here: Home / Swift / Intermediate Swift – Chapter 2.3 Structures

Intermediate Swift – Chapter 2.3 Structures

November 5, 2018 by Kenneth Jackson Leave a Comment

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)

Share this:

  • Share
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on WhatsApp (Opens in new window) WhatsApp

Filed Under: Swift Tagged With: Amarillo, Swift 4.2, Texas

Leave a ReplyCancel reply

  • Facebook
  • GitHub
  • Twitter
  • YouTube

Kenneth Jackson

(806) 374-2323
Please leave a voice or text message.

Contact Kenneth

Recent Posts: KennethJackson.Tech

Effects Design – Jon Dattorro – Notes

Erica Synths – EDU DIY Hi-Hat – Notes

Erica Synths – EDU DIY Snare Drum – Notes

Erica Synths – EDU DIY Kick Drum – Notes

Ornament and Crime (o_C) – Notes

  • Facebook
  • Twitter
  • YouTube
  • GitHub
  • Discord
  • Contact Me
  • Payments
  • Privacy Policy

Copyright © Kenneth Jackson

Designed by Kenneth Jackson in Amarillo, Texas

Powered by WPplaces