大規模アプリにおけるXcode Previews実用化までの道のり

Sho Ikeda
September 20, 2025

大規模アプリにおけるXcode Previews実用化までの道のり

Sho Ikeda

September 20, 2025

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

48 slides
  1. @ikesyo / Sho Ikeda • ͍͚͠ΐʔʗ஑ా ᠳ • LINEϠϑʔגࣜձࣾ /

    MDX Team of LINE app • https://github.com/ikesyo • Swift Contributor / Various OSS Contributor • iOSDCొஃ • LT5ճʢ2016-2019ɺ2023ʣ • ϨΪϡϥʔτʔΫ͸ࠓճ͕ॳΊͯ 2
  2. LINE iOSͱStatic Framework • ඇৗʹଟ͘ͷϞδϡʔϧ͕͋ΔͷͰɺDynamic LinkͩͱΞϓϦͷىಈ ͕࣌ؒ஗͘ͳͬͯ͠·͏ • → Static

    FrameworkԽͯ͠࢖༻ • ͔͠͠Xcode 15.x·Ͱ͸Dynamic FrameworkͰͳ͍ͱͦͷϞδϡʔ ϧΛPreviewͰ͖ͳ͔ͬͨ • Xcode Previewsͷ࣮ߦΤϯδϯͷ੍ݶ • → LINE iOSΞϓϦͰ͸ࣄ্࣮Preview͕࢖͑ͳ͔ͬͨ 9
  3. Static FrameworkͱXcode 16 • Xcode 15·Ͱ: Dynamic FrameworkͰ͔͠Preview͕ಈ͔ ͳ͍ •

    Xcode 16.0Ͱ͍ͭʹStatic Frameworkͷαϙʔτ͕௥Ճ͞Ε ͨ͜ͱΛ೺Ѳ͠ɺݕূΛ։࢝ • https://developer.apple.com/ documentation/xcode-release- notes/xcode-16-release-notes 11
  4. Static FrameworkͱXcode 16 • ·ͣ͸طଘͷϞδϡʔϧͰ͸ͳ͘ɺඞཁ ࠷খݶͷϞδϡʔϧΛ࡞ͬͯࢼͯ͠ΈΔ • ͔֬ʹStatic FrameworkͰ΋Preview ͕ಈ͘͜ͱΛ֬ೝ

    ! • ͨͩ͠ɺ৽͍࣮͠ߦΤϯδϯΛ࢖͏ ඞཁ͕͋Δ • Editor → Canvas → Use Legacy Previews Execution ΛΦϑʹ͢ ΔʢແޮԽʣ 12
  5. Static FrameworkͱXcode 16 • ͔͠͠طଘͷϞδϡʔϧͰ΋ݕূͯ͠ΈΔͱɺavailableΛ࢖͏ͱ Preview͕Ϋϥογϡ͢Δ͜ͱΛൃݟ • Өڹൣғ͕େ͖͘ɺ͜ͷ໰୊͕௚Βͳ͍ͱLINEΞϓϦͰ͸࣮༻Ͱ͖ ͳ͍Ϩϕϧ •

    AppleʹFeedbackΛग़ͨ͠ͷͰɺमਖ਼Λ଴ͭ೔ʑ • FB16037528: Xcode Previews in static frameworks (using the new Execution) failed to run if availability checking is used 13
  6. FB16037528 import SwiftUI struct MyLabel: View { var body: some

    View { if #available(iOS 18, *) { Text("aaa") } } } #Preview { MyLabel() } 14
  7. Static FrameworkͱXcode 16 • Xcode 16.3Ͱ͍ͭʹͦͷόά ͕मਖ਼͞ΕΔ ! • https://

    developer.apple.com/ documentation/xcode- release-notes/xcode-16_3- release-notes Fixed: Previews in static libraries that used @availability annotations would fail with a symbol not found error. This should now be resolved but if you continue to experience this please file a new feedback with fresh diagnostics since we’ve added new logging for triage. (140898299) (FB16037528) 15
  8. 16

  9. ղܾࡦ: XcodeGenͷScheme Managementͷshared/ isShown • https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#scheme- management • shared: Bool

    - indicates whether the scheme is shared • isShown: Bool - indicates whether the scheme is shown in the scheme list • sharedͳϏϧυεΩʔϜͱͯ͠࡞੒ɾڞ༗ͭͭ͠ɺσϑΥϧτͰ͸ඇදࣔͷঢ়ଶʹ͓ͯ͘͠ • → ֘౰ͷϞδϡʔϧΛ։ൃɾϓϨϏϡʔ͍ͨ͠։ൃऀ͕ࣗ෼ͷखݩͰ͚ͩදࣔঢ়ଶʹมߋ͢ Δ • ϏϧυεΩʔϜͷදࣔɾඇදࣔͷঢ়ଶ͸Ϣʔβʔ͝ͱʹ؅ཧ͞ΕΔ • *.xcodeproj/xcuserdata/*.xcuserdatad/xcschemes/xcschememanagement.plist 25
  10. 26

  11. ղܾࡦ: PreviewableUIϞδϡʔϧ • PreviewableUI: ϩδοΫϨεͳUIί ϯϙʔωϯτͷΈ • ґଘੑ஫ೖ: ϩδοΫ΍ΞΫγϣϯ͸ Ϋϩʔδϟ΍όΠϯσΟϯάͰ஫ೖ

    • ܰྔԽ: UIίϯϙʔωϯτߏங༻ͷ࠷ খݶͷґଘʹཹΊΔ → ґଘ͕ଟ͍طଘϞδϡʔϧͰϓϨϏ ϡʔΛ࢖͍͍ͨ࣌΍ɺ৽نͷϞδϡʔϧ ʹରͯ͠ਪ঑ 31
  12. ը૾΍ϩʔΧϦθʔγϣϯͳ ͲͷϦιʔεͷಡΈࠐΈ → ͜ΕͩͱɺͦΕΒͷϦιʔεΛ࢖༻͢ΔUI ϞδϡʔϧͷPreviewͰΫϥογϡͨ͠Γɺϩ ʔΧϥΠζ͕ਖ਼͘͠දࣔ͞Εͳ͘ͳΔɻ • Xcode Previewsͷ࣮ߦ؀ڥ͸ XCPreviewAgent.app

    ͱ͍͏ΞϓϦ͕ϗε τʹͳ͍ͬͯͯɺ Bundle.main ͸͜ͷΞϓ ϦΛࢦ͢ • → ͜ͷΞϓϦʹ͸౰વඞཁͳϦιʔε͕ຒ Ίࠐ·Ε͍ͯͳ͍ͷͰɺϦιʔε͕ݟ͔ͭΒ ͳ͍ 34
  13. ղܾࡦ: Development AssetsΛ࢖ͬ ͯΞΫηαʔίʔυͷڞ௨Ϟδϡʔϧʹ ϦιʔεΛຒΊࠐΉ • Xcode GUI: ϓϩδΣΫτ಺ͷ֤λʔ ήοτͷઃఆͷ

    General → Development Assets • DEVELOPMENT_ASSET_PATHS ͱ͍͏ Build SettingͰ΋ઃఆՄೳ 36
  14. ղܾࡦ: Development AssetsΛ࢖ͬͯΞΫηαʔίʔυͷڞ ௨ϞδϡʔϧʹϦιʔεΛຒΊࠐΉ #if DEBUG let isInPreviews = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"]

    == "1" if isInPreviews { // Xcode Previewsͷ࣮ߦ؀ڥͰ͸ `Bundle(for: BundleFinder.self)` ͕ // Derived Dataͷதͷ `Debug-iphonesimulator` (`BUILT_PRODUCTS_DIR` ૬౰) Λฦ͢ɻ if let bundle = Bundle(for: BundleFinder.self) .url(forResource: "SharedUICommonMediaAssets", withExtension: "framework") .flatMap(Bundle.init(url:)) { return bundle } } return Bundle.main #else return Bundle.main #endif 38
  15. ղܾࡦ: Development AssetsΛ࢖ͬͯΞΫηαʔίʔυͷڞ ௨ϞδϡʔϧʹϦιʔεΛຒΊࠐΉ Ұ෦ͷϞδϡʔϧͰΞΫηαʔίʔυͷڞ௨Ϟδϡʔϧܦ༝Ͱ͸ͳ͘ɺ UIImage(named: ...) Ͱ௚઀ Bundle.main Λࢀর͍ͯͨ͠΋ͷ΋௚͢ɻ

    // NG: σϑΥϧτͷ `in bundle: Bundle? = nil` ͩͱ // `Bundle.main` ͕࢖ΘΕͯ͠·͏ɻ UIImage(named: "button_type_lightgreen_normal") // → nil // OK: PreviewͰ͸ࠩ͠ସ͑ͨBundle͕࢖ΘΕΔɻ // `UIImage(named: "button_type_lightgreen_normal", in: bundle)` UIImage.buttonTypeLightgreenNormal 39
  16. ݱࡏͷঢ়گ • ✅ Static FrameworkͰͷಈ࡞ݕূ • ✅ ʢຊ೔঺հͨ͠Α͏ͳʣ༷ʑͳԼ४උ • ✅

    ΨΠυϥΠϯͷ࡞੒ • ✅ ։ൃνʔϜ΁ͷΞφ΢ϯε • " ֤։ൃνʔϜɾػೳ։ൃͰͷ࣮ફ • ݱ࣌఺ͰPreviewableTarget͸5݅ʢΞφ΢ϯε͔Β3݅૿Ճʣ 41
  17. ࠓޙͷల๬ • Mergeable Libraryͷݕ౼ • Static FrameworkͰ͋Δ͕ނʹɺґଘϞδϡʔϧͷଟ͞ʹΑͬͯPreview ͷಈ࡞͕ෆ҆ఆʹͳͬͨΓɺϞδϡʔϧ෼ׂΛڧ͍ΒΕͨΓ͍ͯ͠Δ ʢՄೳੑ͕͋Δʣ •

    → Mergeable LibraryΛಋೖ͢ΔͱɺDebugϏϧυͰ͸Dynamic Linkʹ ͳΔͷͰɺϦϯΫىҼͷ໰୊ΛܰݮͰ͖Δ͔΋͠Εͳ͍ • ৄ͘͠͸ Mergeable LibraryͰ ߴ଎ͳΞϓϦىಈΛ࣮ݱ͠Α͏ʂ Λࢀর ʢ@giginetʣ 43
  18. ·ͱΊ • LINE iOSΞϓϦͱ͍͏େن໛ͳΞϓϦͷ։ൃʹXcode PreviewsΛಋೖ࢝͠Ίͨ • ͲͷΑ͏ͳ՝୊͕͋Δͷ͔Λચ͍ग़͠ɺͦΕΒΛௐࠪɾղܾ͠ɺXcodeʹ΋ϑΟʔυ όοΫͯ͠όάΛमਖ਼ͯ͠΋Βͬͨ • Static

    FrameworkͰXcode PreviewsΛ׆༻͢Δʹ͸·ͩ·ͩϋʔυϧ͕͋Δ • Previewsࣗମͷಈ࡞҆ఆੑͷ໰୊ʢ৽͍࣮͠ߦΤϯδϯͷJITίϯύΠϧɾϦϯΫʣ • Ϧιʔεόϯυϧͷѻ͍ • Mergeable Library͕վળࡦʹͳΓಘΔͷͰௐࠪɾݕ౼ΛਐΊ͍ͯ͘ • Զͨͪͷઓ͍͸͜Ε͔Βͩʂ 45
  19. ࢀߟࢿྉ • Previews in Xcode | Apple Developer Documentation •

    Development Assets • Build settings reference | Apple Developer Documentation • Previewing your app’s interface in Xcode | Apple Developer Documentation • XcodeͷDevelopment Assets୳๚ @ikesyo • WWDC Videos • Build programmatic UI with Xcode Previews - WWDC23 - Videos - Apple Developer • Structure your app for SwiftUI previews - WWDC20 - Videos - Apple Developer • Mastering Xcode Previews - WWDC19 - Videos - Apple Developer • Mergeable Library • Configuring your project to use mergeable libraries | Apple Developer Documentation • Mergeable LibraryͰ ߴ଎ͳΞϓϦىಈΛ࣮ݱ͠Α͏ʂ @giginet 46

More Decks by Sho Ikeda

Other Decks in Programming