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

Swift5.1 SwiftUI

Swift5.1 SwiftUI

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

21e251d97f836f77e7dce83fcaf6daff?s=128

ry-itto

July 13, 2019
Tweet

More Decks by ry-itto

Other Decks in Technology

Transcript

  1. 4XJGUͷ৽ػೳͱ 4XJGU6* ձ௡େֶίϯϐϡʔλཧ޻ֶ෦೥ ҏ౻྇໵

  2. ࣗݾ঺հ ҏ౻྇໵ ձ௡େֶ೥ J04 Χϐόϥ

  3. ͦ΋ͦ΋ͳͥ4XJGU w ϝδϟʔόʔδϣϯ͡Όͳ͍͡ΌΜɻ w ͦΕΑΓ4XJGU6*͸Αɻ w 4XJGUͱ͔ڵຯͳ͍Θɻ

  4. ճ౴ w 4XJGUΛ͔͚Δਓ͕νϥοͱݟͯ΋ʮ͑ʁʯͬͯͳΔΑ͏ ͳจ๏͕૿͑ͨ w 4XJGU6*ʹେ͖͘औΓࠐ·Εɺ಺෦Ͱ΋ͨ͘͞Μ৽จ๏͕ ࢖༻͞Ε͍ͯΔ w ॳݟͰ͸ਖ਼௚Θ͚Θ͔ΒΜɻ

  5. 4XJGUͷ৽ػೳ

  6. Կݸ͔ฒ΂ͯΈͨ 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 }
  7. ͑ʁී௨͡ΌͶʁ

  8. ͖ͬ͞ͷίʔυͷதͷ৽ػೳ w !1SPQFSUZ%FMFHBUF w !@GVODUJPO#VJMEFS w 0QBRVF3FTVMU5ZQF w ؔ਺ͷฦΓ஋ͰҰߦͰࡁΉ৔߹ʹASFUVSOAΛॻ͔ͳͯ͘ ΋Α͘ͳͬͨ

  9. !1SPQFSUZ%FMFHBUF @ObjectBinding ← ͜Εͱ͔ @State ← ͜Ε KotlinͷҠৡϓϩύςΟʁΛݩʹͯ͠ΔͱͷهࣄΛͪΒͬͱΈͨΓ

  10. !1SPQFSUZ%FMFHBUF ࢖͍ํɿ @State var profile = Profile.default Ͳ͏ͳͬͯΔͷ͔ɿ @Stateͷ৔߹ɺprofileʹೖͬͨ஋ΛBinding<Profile>ͱ͍ͬͨ෩ʹϥο ϓ͢Δɻ

    औΓग़͢ࡍʹ `profile`ͰΞΫηε͢ΔͱೖΕͨ஋, `$profile`ͱΞΫηε͢Δͱϥοϓͨ͠஋Λར༻Ͱ͖Δ
  11. !@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
  12. !@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!!
  13. !@GVODUJPO#VJMEFS w ໰୊఺ print(build { let name = "Ryoya Ito"

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

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

    func hoge() -> some AnyObject { } ͱॻ͚ΔΑ͏ʹͨ͠΋ͷɻ γϯλοΫεγϡΨʔͰ͢ɻ
  16. 0QBRVF3FTVMU5ZQF func hoge() -> AnyObject { } ↑͜ΕͰΑ͘Ͷʁ ͍͍͑ɻ func

    hoge() -> some AnyObject { } ͬͪ͜Ͱ͢ɻ
  17. 0QBRVF3FTVMU5ZQF ͳͥμϝͳͷ͔ʁ ઌ΄Ͳࡌ͍ͤͯͨهࣄʹ౴͑͸͋Δ

  18. 0QBRVF3FTVMU5ZQF w ύϑΥʔϚϯε্ͷϩε͕ൃੜ͢Δɻ 1SPUPDPMͰͷฦΓ஋ʹ͢Δͱ༧ظ͞ΕΔશͯͷܕʹ ରԠՄೳͳΑ͏ʹϝϞϦྖҬ͕֬อ͞ΕΔ

  19. ؔ਺ͷฦΓ஋ͰҰߦͰࡁΉ৔߹ʹ ASFUVSOAΛॻ͔ͳͯ͘΋Α͘ͳͬͨ func add(x: Int, y: Int) -> Int {

    x + y } ͦͷ·Μ·Ͱ͢ɻ ࠓ·ͰΫϩʔδϟͰͰ͖ͨ΋ͷ͕ͦͷ··ؔ਺ͰͰ͖ΔΑ͏ ʹͳΓ·ͨ͠ɻ
  20. ͦͷଞؾʹͳΔΞοϓσʔτ w $PSF/'$Ͱ4VJDBͳͲͷಡΈऔΓ͕Մೳʹͳͬͨ
 ˠJ1IPOFʹ4VJDB΍OBOBDPΛ͚ۙͮΔ͚ͩͰ࢒ߴͷ֬ೝ ͕Ͱ͖Δʂʂ w EZOBNJD.FNCFS-PPLVQͷ,FZ1BUIରԠ

  21. ͓·͚ IUUQTHJUIVCDPNSZJUUPFWFSZUIJOH@DPVOUFS

  22. ͋Γ͕ͱ͏͍͟͝·͠ ͨʂʂ