• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Home
  • Shop
  • Blog
  • Showing Off
    • Galleries
    • Showcase
    • Testimonials
  • Contact
  • About

Connections.Digital

Media Production, Mobile Web and iOS Development

  • Facebook
  • Twitter
  • YouTube
  • GitHub
  • Live Audio and Video Production
    • Video Production
    • Cartage Services
    • Mobile Studio Gear List
    • Stage/Mixer Routing
  • Web Design
    • Mobile WordPress Web Design
    • WordPress Website Design Process
    • WordPress Tutorials
    • Internet Marketing
    • Website Design Terms of Service
  • IT Services

November 5, 2018

Intermediate Swift – Chapter 2.3 Structures

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)

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

Reader Interactions

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Sign up for Connections.Digital

* = required field

powered by MailChimp!

Customer Service

  • My Account
  • Checkout
  • Payments
  • Website Design Terms of Service
  • Terms of Service
  • Privacy Policy
  • Advertisements

Recent Posts

  • Cowtown Opry Buckaroos – Canyon, Texas – October 8, 2022 – Full Show
  • Danny Freeze & Dr. T – Songwriters in the Canyon – July 13, 2022 – Full Show (Sorta)
  • Michael D Coon – Pampa, Texas – September 30, 2022
  • Songwriters in the Round – Chalice Abbey – July 16, 2022
  • Keitha Jones – Grandma – Songwriters in the Canyon – June 15, 2022

Categories

Connections.Digital

Amarillo, Texas 79119
(806) 374-2323

Copyright © Connections Information Systems

Designed by Kenneth Jackson at Connections.Digital in Amarillo, Texas

Powered by WPplaces