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

FunctionBuildersから見るSwiftUIの文法

 FunctionBuildersから見るSwiftUIの文法

SwiftUIの文法の難しいところをFunctionBuildersやその他のSwiftの文法から解説しています。
型がどうなっているのかに着目するとジェネリクスのパワフルさが見えて感動します。

kojiaomatsu

July 12, 2019
Tweet

More Decks by kojiaomatsu

Other Decks in Programming

Transcript

  1. struct ContentView: View { var body: some View { VStack(alignment:

    .leading) { Text("Turtle Rock") .font(.title) HStack { Text("Joshua Tree National Park") .font(.subheadline) Spacer() Text("California") .font(.subheadline) } } .padding() } } &YBNQMF
  2. // Computed Property var hoge : Int { get {

    return 3 } } // Shorter version var hoge : Int { return 3 } // Shortest version var hoge : Int { 3 } // This above explains this part struct ContentView: View { var body: some View { VStack(alignment: .leading) { .. } } } &YBNQMF
  3. 'VODUJPOCVJMEFST @_functionBuilder struct Hoge { static func buildBlock(_ a: Int,

    _ b: Int) -> Int { return a + b } } func fuga(@Hoge a: () -> Int) -> Int { return a() } let puni = fuga { 76 33 } print(puni) // 109
  4. HStack { Text("Joshua Tree National Park") Spacer() Text("California") } 4XJGU6*ͷܕΛݟ͍ͯ͘

    HStack<TupleView<(Text, Spacer, Text)>> var body: some View { VStack(alignment: .leading) { Text("Turtle Rock") HStack { .. } } } VStack<TupleView<(Text, HStack<TupleView<(Text, Spacer, Text)>>)>>
  5. struct ContentView: View { var body: some View { VStack(alignment:

    .leading) { Text("Turtle Rock") .font(.title) HStack { Text("Joshua Tree National Park") .font(.subheadline) Spacer() Text("California") .font(.subheadline) } } .padding() } } ׬શʹཧղͰ͖Δ