Upgrade to Pro — share decks privately, control downloads, hide ads and more …


Dc00a8afd9d3773a8fd0a3f415edba73?s=47 Kane Liu
September 26, 2019



Kane Liu

September 26, 2019

More Decks by Kane Liu

Other Decks in Technology


  1. SwiftUIߟ࡯ #CA.swift Ryu Ka, @Cats, iOS/Android Engineer LBOFMJV LBOF@MJV

  2. 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
  3. 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)
  4. 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
  5. Lifecycle of SwiftUI ɾLoadView ɾviewDidLoad ɾviewWillAppear ɾviewWillLayoutSubviews ɾviewDidLayoutSubviews ɾviewDidAppear ɾviewWillDisappear

 ɾ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
  6. Data Flows ɾCombine Framework ɾProperty Wrappers

  7. State & Data Flows

  8. State & Data Flows ɾ@State - Simple Properties like Strings,

    Integers, and Booleans - Belongs to a single view - use private 
 - Complex properties like custom types
 - Sharing data in many views
 - Required for reference types 
 - Properties created elsewhere such as shared data
 - App crashes if it is missing
  9. Hosting Controller ɾUse HostingController to Show SwiftUI View ɾShow HostingController

    from UIViewController (push, present, addChild)
  10. Wrap UIKit to SwiftUI ɾRepresentable Protocol

  11. Wrap UIKit to SwiftUI

  12. New Design Tools ɾDrag & Drop

  13. New Design Tools ɾDynamic Replacement

  14. Reasons for SwiftUI ɾSave Code & Save Time ɾNo Storyboard,

    No AutoLayout 
 ɾBetter to Building UI ɾBetter to use Data Flow ɾDynamic Preview
  15. 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
  16. #VU

  17. 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
  18. Thank you for listening!!!