Add custom views and modifiers to the Xcode Library

Add custom views and modifiers to the Xcode Library

5d0a36a99b7fa2731c2bf1ad56ed1e6f?s=128

struuuuggle

July 09, 2020
Tweet

Transcript

  1. Add custom views and modifiers to the Xcode Library @struuuuggle

    2020/07/09 SwiftѪ޷ձεϐϯΦϑ WWDC20ηογϣϯཁ໿ձ @ΦϯϥΠϯ
  2. ࣗݾ঺հ

  3. ࠓ೔࿩͢͜ͱ • Xcode LibraryΛ࢖༻͢Δ̏ͭͷϝϦοτ • ࢖༻࣌ʹؾΛ͚ͭΔ͜ͱ̎ͭ


  4. ઌʹ݁࿦

  5. Xcode Libraryʹࣗ࡞ͨ͠View΍ViewModifierΛ ௥ՃͰ͖ΔΑ͏ʹͳΔ
 ηογϣϯλΠτϧΛ΄΅ͦͷ··࿨༁͚ͨͩ͠ Xcode LibraryΛ࢖͏ͱ؆୯ʹΞηοτΛ
 ݺͼग़ͤΔΑ͏ʹͳΔ
 γϣʔτΧοτҰͭͰݺͼग़ͤΔ
 υϥοά&υϩοϓʹΑΔݺͼग़͠΋Մೳ ※Ξηοτ:

    ͜͜Ͱ͸View, Modifier, Snippet, Media, ColorΛࢦ͢ ݁࿦
  6. Xcode LibraryΛ࢖͏̏ͭͷϝϦοτ

  7. Discoverability ΞηοτΛ୳͠΍͍͢ Learning Ξηοτͷ࢖͍ํΛ؆୯ʹֶ΂Δ Visual Editing υϥοά&υϩοϓͰΞηοτΛ൓өͰ͖Δ ※Ξηοτ: ͜͜Ͱ͸View, Modifier,

    Snippet, Media, ColorΛࢦ͢ Xcode LibraryΛ࢖͏̏ͭϝϦοτ
  8. ඞཁͳ΋ͷ

  9. LibraryContentProviderʹద߹ͨ͠ܕ ඞཁͳ΋ͷ

  10. LibraryContentProviderͷத਎

  11. ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ

  12. ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ

  13. ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ

  14. ←ࣗ࡞ͨ͠View ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ

  15. Ҿ਺ʹ͸ݺͼग़ͨ͠ͱ͖ͷ σϑΥϧτ஋Λઃఆ͓ͯ͘͠ ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ

  16. categoryʹ͸.layoutΛࢦఆͯ͠ΈΔ ※.layoutͷଞʹ͸.effect, .control, .other͕͋Δ → LibraryItem.Categoryࢀর ※LibraryItemͷinitializerʹ͸ଞʹ΋Ҿ਺͕ଘࡏ͢Δ → visible, title,

    matchingSignature ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ
  17. ࣮૷ͯ͠ΈΑ͏ ʙViewฤʙ Library(⌘+ Shift+L)Λ։͘ͱɺઌఔ ௥Ճͨ͠NoteListRow͕ީิʹग़ͯ͘ Δ

  18. ࣮૷ͯ͠ΈΑ͏ ʙView Modifierฤʙ

  19. Viewͷͱ͖ͱಉ͡Α͏ʹ LibraryItemΛఆٛ͢Δ ࣮૷ͯ͠ΈΑ͏ ʙView Modifierฤʙ

  20. γάωνϟ͸ modifiers(base:) -> [LibraryItem] ࣮૷ͯ͠ΈΑ͏ ʙView Modifierฤʙ

  21. ModifierΛ෇༩͢ΔViewͷ छྨΛࢦఆ͢Δ ࣮૷ͯ͠ΈΑ͏ ʙView Modifierฤʙ

  22. 1. ࣗ࡞ͨ͠ModifierΛ౉͢ 2. Ҿ਺ʹ͸σϑΥϧτ஋Λॻ͍͓ͯ͘ ࣮૷ͯ͠ΈΑ͏ ʙView Modifierฤʙ

  23. ݺͼग़ͯ͠ΈΑ͏

  24. ݺͼग़ͯ͠ΈΑ͏ ͜͜ʹࣗ࡞ͨ͠.style(_:) Λࠩ͠ࠐΈ͍ͨʂ

  25. ݺͼग़ͯ͠ΈΑ͏ ͓΋ΉΖʹ㵰+Shift+LΛԡͯ͠ɺ .style(_:)Λ୳͢

  26. ݺͼग़ͯ͠ΈΑ͏ ૠೖ׬ྃ

  27. ؾΛ͚ͭΔ͜ͱ̎ͭ

  28. Canvas͸։͍͓ͯ͘ ※Xcode Version 12.0 beta 2 (12A6163b)ͷڍಈ

  29. 1. Canvas͸։͍͓ͯ͘ Canvasදࣔ࣌

  30. 1. Canvas͸։͍͓ͯ͘ LibaryContentProvider:viewsͰ࣮૷ ͨ͠NoteListRow͕ଘࡏ͢Δ Canvasදࣔ࣌

  31. 1. Canvas͸։͍͓ͯ͘ LibaryContentProvider:viewsͰ࣮૷ ͨ͠NoteListRow͕ଘࡏ͢Δ Canvasඇදࣔ࣌

  32. 1. Canvas͸։͍͓ͯ͘ LibaryContentProvider:viewsͰ࣮૷ ͨ͠NoteListRow͕ଘࡏ͢Δ Canvasඇදࣔ࣌ ViewsͱModifiers͕͍ͳ͍⚡

  33. 2. LibraryContentͷ؅ཧ

  34. AppleެࣜͷαϯϓϧίʔυͰ͸ɺ HogeViewʹରͯ͠HogeViewLibraryContent ͱ͍͏ߏ଄ମΛ࡞੒͍ͯ͠Δ →ComponentຖʹLibraryContentΛ࡞੒ͯ͠ΈΑ͏ ਖ਼௚ख୳ΓͳͷͰ͜ͷ͋ͨΓͷϓϥΫςΟεʹ͍ͭͯੋඇҰॹʹٞ࿦͠·͠ΐ͏ 2. LibraryContentͷ؅ཧ

  35. ·ͱΊ

  36. LibraryContentProviderʹద߹ͨ͠ܕΛ༻ҙ →LibraryItemܦ༝ͰΞηοτΛXcode Libraryʹ௥Ճ Xcode Libraryʹ௥Ճͨ͠Ξηοτ͸؆୯ʹݺͼग़͠Մೳ →Xcode Previewͱͷ૬ੑ˕ υΩϡϝϯτ΍ίʔυΛړͬͯΞηοτΛ୳͢ख͕ؒল͚Δ →େن໛ϓϩδΣΫτͰͦ͜ޮՌΛൃش →৽ϝϯόʔͷΦϯϘʔσΟϯάʹ΋ߩݙͦ͠͏

    ·ͱΊ
  37. ࢀߟ • Add custom views and modifiers to the Xcode

    Library - WWDC20 • LibraryContentProvider - Apple Developer Documentation • LibraryContentBuilder - Apple Developer Documentation • Xcode 12 Beta 2 Release Notes
  38. ิ଍

  39. WWDC19௚ޙʙXcode11.0҆ఆ൛͕ग़Δ·ͰɺSwiftUI΍ Combine Framework౳ͷAPIʹ͸େ͖ͳมߋ͕͋ͬͨ ೋ࣍৘ใΛࢀর͢Δͱ͖͸࠷ऴߋ৽೔࣌ΛඞͣνΣοΫ͠Α͏ ͜ͷεϥΠυͷফඅظݶ͕੾ΕΔՄೳੑ΋ेೋ෼ʹ͋Δ Ұ࣍৘ใʹ৮Εͯɺৗʹ࠷৽ͷ৘ใʹΩϟονΞοϓ͠Α͏ ͓·͚

  40. @LibraryContentBuilderͷ͓ӄͰɺLibraryContentProviderͷviewsΛ ഑ྻͬΆ͞ͳ͠ʹఆٛͰ͖Δ @LibraryContentBuilder ͋Γ @LibraryContentBuilder ͳ͠

  41. ίϯύΠϥͷ͓ӄͰ… • Distribution༻ͷϏϧυΛߦ͏ͱ͖ʹ͸ίϯύΠϥ͕ LibrayContentProviderͷ෦෼ΛಡΈඈ͹ͯ͘͠ΕΔ →#if DEBUG … #fi ͸ෆཁ •

    ࣗ࡞ͨ͠ΞηοτͷAPI͕มΘͬͯ΋ɺXcode Library͕ ػೳ͢ΔΑ͏ʹίϯύΠϥ͕αϙʔτͯ͘͠ΕΔ →ίϯύΠϧΤϥʔΛ௚ͤ͹Xcode Library͸ͦͷޙ΋ػೳ͢Δ