Structs and Classes
Struct Properties
Structs group related values into one named type with stored properties.
Group related values
struct_properties.swift
struct Book {
let title: String
let pages: Int
}
let pageCount =
let book = Book(title: "Swift Notes", pages: pageCount)
let summary = "\(book.title): \(book.pages)"
print(summary)
struct Book {
let title: String
let pages: Int
}
let pageCount =
let book = Book(title: "Swift Notes", pages: pageCount)
let summary = "\(book.title): \(book.pages)"
print(summary)
struct Book {
let title: String
let pages: Int
}
let pageCount =
let book = Book(title: "Swift Notes", pages: pageCount)
let summary = "\(book.title): \(book.pages)"
print(summary)
structs
A struct instance stores each property value together. Dot syntax reads the stored properties from that instance.