Skip to content

Latest commit

 

History

History
192 lines (127 loc) · 4.91 KB

File metadata and controls

192 lines (127 loc) · 4.91 KB

Exploring SwiftUI

Learning Objectives

By the end of this lesson, students should be able to:

  • Familiarize with Apple's frameworks for UI
  • Explain what is SwiftUI and how it works with Declarative syntax
  • Build layouts using stacks
  • Create views efficiently using Swift's constructs

Frameworks for UI

SwiftUI

swiftui

SwiftUI is an innovative way to build user interfaces across all Apple platforms using Swift.

Declarative syntax

Declarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed.

Telling SwiftUI what we want the UI to look like and work, then it figures out how to make that happen.

  • Easy to read
  • Natural to write

UIKit and SwiftUI

Side by Side

homecook

chef

Design Tools

With Xcode 11 came a lot of new tools to work with SwiftUI.

As we work in the code editor, we get to see a live preview of the app.

As we work in the design canvas, everything we edit is in sync with the code editor.

In any case, Xcode recompiles the changes instantly and inserts them into a running version of your app, visible, and editable at all times.

Some facts

  • SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6. And future versions of each.
  • SwiftUI is faster than UIKit.
  • You can have a project than mixes SwiftUI and UIKit.
  • SwiftUI does not replace UIKit.

What should we learn?

For now SwiftUI has limited API coverage, limited adoption and support.

It will be a big deal in years to come (maybe 2 or 3). But as iOS developers in the job industry now, we need to know about UIKit as a requirement.

The best option is to learn SwiftUI on the side as well.

Stacks 📚

designcode.io explanation for stacks

Live demo

  1. Finding the preview
  2. Template contents
  3. Hello world
  4. Hello world in an HStack
  5. Hello world in a VStack
  6. Grid with text
  7. Add image
  8. Simulator

Warmup

  • Replicate this layout and write your own text at the bottom.
  • Find the thread in our Slack channel and post a screenshot when you are done.

warmup

In Class Activity

Instructions here

Additional Resources