Book description
What will you learn from this book?
Swift is best known as Apple's programming language of choice for developing apps on iOS, iPadOS, macOS, watchOS, and tvOS. But it's far more versatile than that. Open source Swift is also gaining ground as a language for systems programming and server-side code, and it runs on Linux and Windows. So where do you start? With Head First Swift, you'll explore from the ground up: from collecting and controlling data to reusing code, producing custom data types, and structuring programs and user interfaces with SwiftUI by building safe, protocol-driven code. With Swift under your belt, you'll be ready to build everything from mobile and web apps to games, frameworks, command-line tools, and beyond.
What's so special about this book?
If you've read a Head First book, you know what to expect--a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. With this book, you'll learn Swift through a multisensory experience that engages your mind rather than a text-heavy approach that puts you to sleep.
Publisher resources
Table of contents
- Authors of Head First Swift
- Table of Contents (the real thing)
- how to use this book: Intro
-
1. Introducing Swift: Apps, Systems, and Beyond!
- Swift is a language for everything
- The swift evolution of Swift
- Swift into the future
- How you’re going to write Swift
- The path you’ll be taking
- Getting Playgrounds
- Creating a Playground
- Using a Playground to code Swift
- Basic building blocks
- A Swift example
- Here’s what you need to build
- The print function
- 1 Building a list of ingredients
- 2 Picking four random ingredients
- 3 Displaying our random pizza
- Congrats on your first steps with Swift!
- Swiftcross
- Swiftcross Solution
- 2. Swift by Name: Swift by Nature
-
3. Collecting and Controlling: Going Loopy for Data
- Sorting pizzas
- Swift collection types
- Collecting values in an array
- How big is that array, exactly? Is it empty?
- Collecting values in a set
- Collecting values in a dictionary
- Tuples
- Everyone needs a good alias
- Control flow statements
- if statements
- switch statements
- Building a switch statement
- Range operators
- More complex switch statements
- Getting repetitive with loops
- Building a for loop
- Building a while loop
- Building a repeat-while loop
- Solving the pizza-sorting problem
- Phew, that’s a lot of Swift!
- Code Magnets
- Pool Puzzle
- BE the Swift Compiler
- Swiftcross
- Code Magnets Solution
- Pool Puzzle Solution
- BE the Swift Compiler Solution
- Swiftcross Solution
-
4. Functions and Enums: Reusing Code on Demand
- Functions in Swift let you reuse code
- Built-in functions
- What can we learn from built-in functions?
- Improving the situation with a function
- Writing the body of the function
- Using functions
- Functions deal in values
- Many happy returns (from your functions)
- A variable number of parameters
- Fireside Chats
- What can you pass to a function?
- Every function has a type
- Function types as parameter types
- Multiple return types
- Fireside Chats
- Functions don’t have to stand alone
- Switching with enums
- Functioncross
- Functioncross Solution
-
5. Closures: Fancy, Flexible Functions
- Meet the humble closure
- Closures are better with parameters
- Boiling it all down to something useful
- Reducing with closures
- Capturing values from the enclosing scope
- Escaping closures: the contrived example
- Autoclosures provide flexibility
- Shorthand argument names
- Closurecross
- BE the Swift Compiler
- Closurecross Solution
- BE the Swift Compiler Solution
-
6. Structures, Properties, and Methods: Custom Types and Beyond
- Let’s make a pizza, in all its glory...
- Under the hood...
- The initializer behaves just like a function
- Methods inside structures
- Changing properties using methods
- Computed properties
- Code Magnets
- Getters and setters for computed properties
- Implementing a setter
- Swift Strings are actually structs
- The case for lazy properties
- Using lazy properties
- Structcross
- Structcross Solution
- Code Magnets Solution
-
7. Classes, Actors, and Inheritance: Inheritance Is Always a Thing
- A struct by any other name (that name: a class)
- Inheritance and classes
- Replacing Overriding methods
- Under the hood...
- Final classes
- Automatic reference counting
- Mutability
- Swift Safety
- Fireside Chats
- BE the Swift Compiler
- Pool Puzzle
- Classcross
- Pool Puzzle Solution
- BE the Swift Compiler Solution
- Classcross Solution
-
8. Protocols and Extensions: A Swift Lesson in Protocol
- The Robot Factory
- Protocol inheritance
- Mutating methods
- Protocol types and collections
- Computed properties in extensions
- Extending a protocol
- Useful protocols and you
- Conforming to Swift’s protocols
- Code Magnets
- Protocolcross
- BE the Swift Compiler
- Code Magnets Solution
- Protocolcross Solution
- BE the Swift Compiler Solution
-
9. Optionals, Unwrapping, Generics, and More: Nothing Optional About It
- Optionals Exposed
- Dealing with something that’s missing
- Why you might need an optional
- Optionals and handling missing data
- Unwrapping optionals
- Unwrapping optionals with guard
- Force unwrapping
- Swift Safety
- BE the Swift Compiler
- Swift Safety
- Generics
- A queue with generics
- Here’s our new Queue type
- Optionalcross
- Optionalcross Solution
- BE the Swift Compiler Solution
-
10. Getting Started With Swiftui: User Interfaces…Swiftly
- What’s a UI framework, anyway?
- Your first SwiftUI UI
- UI building blocks
- Making a list, checking it…quite a few times, to get it perfect
- User interfaces with state
- Buttons are for pressing
- Let’s see how far you’ve come
- Customizing your views with modifiers
- Create a new SwiftUI Xcode project, for iOS
- Your Xcode will look something like this
- Create a new type to store a todo item in
- Make sure each todo item can be uniquely identified
- Create a user interface for the app
- Create a user interface for the app, continued, continued
- Test Drive
- Implement a way to save the list of todos
- So, that’s a UI framework?
- SwiftUIcross
- Pool Puzzle
- BE the Swift Compiler
- SwiftUIcross Solution
- Pool Puzzle Solution
- BE the Swift Compiler Solution
-
11. Putting Swiftui into Practice: Circles, Timers, Buttons—Oh My!
- What fancy things can be done with a UI framework?
- Create a new SwiftUI Xcode project, for iOS
- The Executive Timer UI and features
- Creating the basic elements of the app
- Pieces of the UI
- Setting up the UI of the Executive Timer
- Coding the pieces of the UI
- Combining the three elements
- The finishing touches
- Test Drive
- Tabbed views for a clean UI
- 1 Create however many different views you need (to live in tabs)
- 2 Build a TabView containing your views
- The resulting tabs
- Creating a new tabbed ContentView
- Creating the tabs and the TabView
- Running your new tabbed Executive Timer
- SwiftUIcross
- SwiftUIcross Solution
-
12. Apps, web, and Beyond: Putting It All Together
- A journey must end...
- A recipe for a welcome screen
- Step by step assembly of the welcome screen
- Smash Share the state
- It’s time for our old friend...
- Building an app with multiple views that share state
- Building a two-view score tracker
- The ObservableObject
- The first view
- The second view
- The first view, again
- A fancy AsyncImage
- Meet Vapor, the Swift web framework
- Sending data over the web with Vapor
- SwiftUIcross
- SwiftUIcross
- SwiftUIcross Solution
- Index
Product information
- Title: Head First Swift
- Author(s):
- Release date: November 2021
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491922859
You might also like
book
Head First Go
What will you learn from this book? Go makes it easy to build software that’s simple, …
book
Head First Git
What will you learn from this book? Many people who use Git rely on "recipes"--copying and …
book
The Go Programming Language
is the authoritative resource for any programmer who wants to learn Go. It shows how to …
book
Learning React, 2nd Edition
If you want to learn how to build efficient React applications, this is your book. Ideal …