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

SwiftUIってこんなやつ

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 SwiftUIってこんなやつ

Avatar for Sato Takeshi

Sato Takeshi

June 13, 2019
Tweet

More Decks by Sato Takeshi

Other Decks in Programming

Transcript

  1. Who am I
 • Name
 • 佐藤剛士(さとうたけし) 
 • Company


    • Merpay, Inc.(2019/01 ~) 
 • Role
 • Software Engineer (iOS) 
 • Account
 • Twitter: @hatakenokakashi 
 • Facebook: 佐藤剛士 
 • GitHub: SatoTakeshiX 

  2. Use the features of Swift5.1
 • Opaque Result Type
 •

    Implicit return from single-expression functions
 • Function Builder

  3. Opaque Result Type
 
 
 • 具体的な型を隠蔽したまま実行時のオーバーヘッドを支払わずに済す方法
 • Swift 5.1

    に導入される Opaque Result Type とは何か
 • some修飾子をつけることでOpaque Result Typeであることを表します。
 
 
struct ContentView: View { var body: some View {// Opaque Result Type! VStack {...} } }

  4. Implicit returns from single-expression functions
 • 今までクロージャーでは1ステートメントならreturnなしで値を返せた
 • それを関数、コンピューテッドプロパティ、subscriptも認める機能
 var

    body: some View { VStack {...} // bodyはVStackというインスタンスを返すコンピューテッドプロパティ } // 上記と下記は同じ意味 var body: some View { get { return VStack{...} } }
  5. Function Builder
 • 独自のAttributeを定義できる
 • SwiftUIではViewBuilderというAttributeを定義している
 @available(iOS 13.0, OSX 10.15,

    tvOS 13.0, watchOS 6.0, *) @_functionBuilder public struct ViewBuilder { /// Builds an empty view from an block containing no statements, `{ }`. public static func buildBlock() -> EmptyView /// Passes a single view written as a child view (e..g, `{ Text("Hello") }`) through /// unmodified. public static func buildBlock<Content>(_ content: Content) -> Content where Content : View }
  6. ViewBuilder
 VStack { MapView() CircleImage() Text("Turtle Rock") } VStack {

    ViewBuilder.buildBlock( MapView(), CircleImage(), Text("Turtle Rock") ) }