a struct called book with the relevant properties in swift

Here's a Swift code snippet to define a Book struct with properties/title, author, and pageCount:

main.swift
struct Book {
  let title: String
  let author: String
  let pageCount: Int
}
78 chars
6 lines

You can then create a new instance of Book with the specified properties as follows:

main.swift
let myBook = Book(title: "The Catcher in the Rye", author: "J.D. Salinger", pageCount: 277)
92 chars
2 lines

And access the properties of the struct with dot notation:

main.swift
print("Title: \(myBook.title)") // Output: Title: The Catcher in the Rye
print("Author: \(myBook.author)") // Output: Author: J.D. Salinger
print("Number of Pages: \(myBook.pageCount)") // Output: Number of Pages: 277
218 chars
4 lines

gistlibby LogSnag