Share
Embed
Transcript
18 slides
-
Introducing SwiftUI ɾAnnounced at WWDC2019 ɾRequires on iOS13.0, MacOS10.15+, tvOS13.0+,
watchOS6.0+, Xcode11 ɾDeclarative Syntax ɾNew Design Tools (Drag & Drop, Dynamic Replacement, Previews) ɾBuild Apps On All Apple Platforms -
What is a SwiftUI View ɾProtocol rather than a class,
no inheritance problems ɾBody return some View (Opaque result types from Swift5.1) ɾView must return one View to render ɾContainer other views, but just on parent view going back ɾCreate layout by Stacks(HStack, VStack, ZStack, Divider, Spacer) -
Migrating from UIKit to SwiftUI ɾUITableView -> List ɾUICollectionView: No
SwiftUI equivalent ɾUILabel: Text ɾUITextFiled: TextFiled ɾUITextFiled with isSecureTextEntry set to true: SecureField ɾUITextView: No SwiftUI equivalent ɾUISwitch: Toggle ɾUISlider: Slider ɾUIButton: Button ɾUINavigationController: NavigationView ɾUIAlertController with style .alert: Alert ɾUIAlertController with style .actionSheet: ActionSheet ɾUIStackView with .horizontal axis: HStack ɾUIStackView with .vertical axis: VStack ɾUIImageView: Image ɾUISegmentedControl: SegmentedControl ɾUIStepper: Stepper ɾUIDataPicker: DataPicker ɾNSAttributedString: Incompatible with SwiftUI, use Text instead -
Lifecycle of SwiftUI ɾLoadView ɾviewDidLoad ɾviewWillAppear ɾviewWillLayoutSubviews ɾviewDidLayoutSubviews ɾviewDidAppear ɾviewWillDisappear
ɾviewDidDisappear ɾviewDidUnload ɾView Initialization ɾState & Data Flow ɾonAppear ɾonDisappear UIViewController’s Lifecycle SwiftUI View’s Lifecycle (Event?) In SwiftUI no longer need to handle so many lifecycle methods anymore -
State & Data Flows ɾ@State - Simple Properties like Strings,
Integers, and Booleans - Belongs to a single view - use private ɾ@ObjectBinding - Complex properties like custom types - Sharing data in many views - Required for reference types ɾ@EnviromentObject - Properties created elsewhere such as shared data - App crashes if it is missing -
Hosting Controller ɾUse HostingController to Show SwiftUI View ɾShow HostingController
from UIViewController (push, present, addChild) -
Reasons for SwiftUI ɾSave Code & Save Time ɾNo Storyboard,
No AutoLayout ɾBetter to Building UI ɾBetter to use Data Flow ɾDynamic Preview -
Need to Consider ɾiOS13+ (Separate Logic under iOS13) ɾMacOS Catalina
to Preview not fast enough (beta9 now) ɾNot able for Complex UIViewController Transition ɾNot able to get Scroll ContentOffset ɾOther bugs Support From 13.0 -
Watch Video on WWDC2019 ɾSession 204 Introducing SwiftUI: Building Your
First App ɾSession 216 Introducing SwiftUI Essentials ɾSession 226 SwiftUI Essentials ɾSession 231 Integrating SwiftUI ɾSession 237 Building Custom Views with SwiftUI ɾSession 238 accessibility in SwiftUI ɾSession 219 SwiftUI on watchOS ɾSession 240 SwiftUI on all Device