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
SwiftUI is an innovative way to build user interfaces across all Apple platforms using Swift.
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
Side by Side
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.
- 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.
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.
designcode.io explanation for stacks
- Finding the preview
- Template contents
- Hello world
- Hello world in an HStack
- Hello world in a VStack
- Grid with text
- Add image
- Simulator
- 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.