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

Swift5.1 SwiftUI

ry-itto
July 13, 2019

Swift5.1 SwiftUI

会津大学 x 日大 LTでの登壇資料です。

ry-itto

July 13, 2019
Tweet

More Decks by ry-itto

Other Decks in Technology

Transcript

  1. Կݸ͔ฒ΂ͯΈͨ struct SwiftUIView : View { var body: some View

    { Text("Hello World!”) Text("Hello World!") } } @ObjectBinding var viewModel: HogeViewModel func add(x: Int, y: Int) -> Int { x + y }
  2. !1SPQFSUZ%FMFHBUF ࢖͍ํɿ @State var profile = Profile.default Ͳ͏ͳͬͯΔͷ͔ɿ @Stateͷ৔߹ɺprofileʹೖͬͨ஋ΛBinding<Profile>ͱ͍ͬͨ෩ʹϥο ϓ͢Δɻ

    औΓग़͢ࡍʹ `profile`ͰΞΫηε͢ΔͱೖΕͨ஋, `$profile`ͱΞΫηε͢Δͱϥοϓͨ͠஋Λར༻Ͱ͖Δ
  3. !@GVODUJPO#VJMEFS var body: some View { Text("Hello World!”) // ͜͜

    Text("Hello World!”) // ͜͜ } 1SPQPTBM https://github.com/apple/swift-evolution/blob/ 9992cf3c11c2d5e0ea20bee98657d93902d5b174/proposals/XXXX- function-builders.md
  4. !@GVODUJPO#VJMEFS ಠࣗͷ֦ு΋࡞ΕΔ(ྫɿ୯ޠΛݸผʹ౉ͯ͠ӳจ࡞੒) @_functionBuilder struct SentenceBuilder { static func buildBlock(_ strs:

    String...) -> String { return strs.reduce(“”) { (res, str) -> String in return res + " " + str } } } func build(@SentenceBuilder block: () -> String) -> String { block() } print(build { "I";"am";"Ryoya Ito";"Nice";"to";"meet";"you!!" }) => I am Ryoya Ito Nice to meet you!!
  5. !@GVODUJPO#VJMEFS w ໰୊఺ print(build { let name = "Ryoya Ito"

    "I" “am" name "Nice" "to" "meet" "you!!" }) ɾΫϩʔδϟ಺Ͱม਺ఆ͕ٛͰ͖ͳ͍ ɾΫϩʔδϟ಺ͰifจͳͲ͕ॻ͚ͳ͍
  6. 0QBRVF3FTVMU5ZQF ͜ͷίʔυதͷ`some` var body: some View { Text("Hello World!") }

    ؆୯ʹදݱ͢ΔͱɺฦΓ஋Ͱ૯শܕΛ࢖͍͍ͨ࣌࢖͏΋ͷɻ શͯ͸͜ͷهࣄʹ͋Δɾɾɾ Swift 5.1 ʹಋೖ͞ΕΔ Opaque Result Type ͱ͸Կ͔
  7. 0QBRVF3FTVMU5ZQF ຊདྷͰ͋Ε͹ func hoge() -> <H:AnyObject> H { } ͜͏ॻ͘ඞཁ͕͋ΔͷΛ

    func hoge() -> some AnyObject { } ͱॻ͚ΔΑ͏ʹͨ͠΋ͷɻ γϯλοΫεγϡΨʔͰ͢ɻ
  8. ؔ਺ͷฦΓ஋ͰҰߦͰࡁΉ৔߹ʹ ASFUVSOAΛॻ͔ͳͯ͘΋Α͘ͳͬͨ func add(x: Int, y: Int) -> Int {

    x + y } ͦͷ·Μ·Ͱ͢ɻ ࠓ·ͰΫϩʔδϟͰͰ͖ͨ΋ͷ͕ͦͷ··ؔ਺ͰͰ͖ΔΑ͏ ʹͳΓ·ͨ͠ɻ