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

Swift Packages and XCFrameworks in Xcode 11

Swift Packages and XCFrameworks in Xcode 11

「帰ってきた関西モバイルアプリ研究会#2」の発表資料です #関モバ

https://kanmoba.connpass.com/event/134059/

Sho Ikeda

June 12, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. Swift Packages and
    XCFrameworks in
    Xcode 11
    Sho Ikeda / @ikesyo
    ؼ͖ͬͯͨؔ੢ϞόΠϧΞϓϦݚڀձ#2
    2019-06-12 Wed
    #ؔϞό

    View full-size slide

  2. Sho Ikeda / @ikesyo
    • ͍͚͠ΐʔʗ஑ా ᠳ
    • ͸ͯͳ@ژ౎
    • εϚʔτϑΥϯΞϓϦ։ൃ
    • iOS / Android / React Native
    • Swiftίϛολʔ
    • https://twitter.com/ikesyo
    • https://github.com/ikesyo

    View full-size slide

  3. Swift Packages

    View full-size slide

  4. Swift Package Manager (SwiftPM)
    • The Package Manager for the Swift Programming Language
    • Introduced in Swift 3 (2016)
    • Package.swift
    • swift package commands
    • swift package init
    • swift package build
    • swift package test
    • swift package generate-xcodeproj
    • For Server-Side Swift, CLI tools, ...

    View full-size slide

  5. SE-0236
    Package Manager Platform Deployment
    Setting
    • https://github.com/apple/swift-evolution/blob/master/proposals/
    0236-package-manager-platform-deployment-settings.md
    • swift package generate-xcodeprojͰੜ੒͞ΕΔ.xcodeproj
    ͷDeployment Targetʹ൓ө
    • Xcode΁ͷ౷߹ͷ෍ੴ

    View full-size slide

  6. // swift-tools-version:5.0
    import PackageDescription
    let package = Package(
    name: "Himotoki",
    platforms: [
    .macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)
    ],
    products: [
    .library(name: "Himotoki", targets: ["Himotoki"]),
    ],
    targets: [
    .target(name: "Himotoki", dependencies: [], path: "Sources"),
    .testTarget(name: "HimotokiTests", dependencies: ["Himotoki"]),
    ],
    swiftLanguageVersions: [.v5]
    )

    View full-size slide

  7. Swift Packages in Xcode 11
    • WWDC19ͷηογϣϯ
    • Adopting Swift Packages in Xcode - WWDC 2019 - Videos - Apple Developer
    • Creating Swift Packages - WWDC 2019 - Videos - Apple Developer
    • [New!] SwiftPMͷػೳ͕Xcodeʹ౷߹͞Εͨ
    • Xcode͔ΒSwift PackageΛ࡞ΕΔΑ͏ʹͳͬͨ
    • Xcode͔ΒSwift PackageͷґଘΛ௥ՃɾղܾͰ͖ΔΑ͏ʹͳͬͨ
    • .xcodeprojͳ͠ͰɺPackage.swift͚ͩͰXcodeΛ։͚ΔΑ͏ʹͳͬͨ
    • ΋ͪΖΜίʔυิ׬΋ಈ͘͠ςετ΋Ͱ͖Δ
    • xcodebuildίϚϯυ΋.xcodeprojͳ͠ͷSwift PackageʹରԠ͍ͯ͠Δ
    • swift package generate-xcodeprojͷඞཁੑ͕ബΕͨ

    View full-size slide

  8. Swift Packages: Known Issues
    • 1ͭͷλʔήοτͰSwiftͱCɺSwiftͱObjective-Cɺͱ͍͏ࠞͥํ͸Ͱ͖ͳ͍
    • λʔήοτΛ෼͚Δඞཁ͕͋Δ
    • Ϧιʔε͕࣋ͯͳ͍
    • ը૾, Ի੠, Storyboard, ϩʔΧϥΠζ༻จࣈྻ, ...
    • όΠφϦ഑෍͸Ͱ͖ͳ͍
    • Package.swiftʹͦ͏͍͏λʔήοτఆٛ͸ͳ͍
    • UIܥͷϥΠϒϥϦʔ΍֤छSDKͰ͸ɺCarthage΍CocoaPods͸·݈ͩࡏͰ͸ͳ͍
    ͔

    View full-size slide

  9. XCFrameworks

    View full-size slide

  10. XCFrameworks
    • WWDC19ͷηογϣϯ
    • What's New in Swift - WWDC 2019 - Videos - Apple Developer
    • Binary Frameworks in Swift - WWDC 2019 - Videos - Apple Developer
    • [New!] ϑϨʔϜϫʔΫͷόΠφϦ഑෍༻ͷ৽ϑΥʔϚοτ
    • .xcframework֦ுࢠ
    • 1ͭͷ.xcframeworkͷதʹෳ਺ͷϓϥοτϑΥʔϜ༻ͷ.frameworkΛόϯυϧ͢Δ
    • macOS, iOS Simulator, iOS Device, UIKit for Mac, tvOS Simulator, tvOS Device,
    watchOS Simulator, watchOS Device

    View full-size slide

  11. XCFrameworks
    Swift 5.1ͷModule Stability
    • SwiftͰॻ͍ͨϑϨʔϜϫʔΫΛόΠφϦ഑෍ͯ͠΋໰୊ͳ͘
    ͳͬͨʢίϯύΠϥʔͷόʔδϣϯҧ͍Ͱ΋ΤϥʔʹͳΒͳ
    ͘ͳͬͨʣ
    • ϑϨʔϜϫʔΫͷόΠφϦ഑෍ͷαϙʔτͷվળ

    View full-size slide

  12. XCFrameworks
    UIKit for Mac
    • ͜Ε·ͰͷόΠφϦ഑෍
    • iOS Deviceͷarmv7ͱarm64ɺiOS Simulatorͷx86_64ʢͱi386ʣΛ1ͭʹ·ͱ
    ΊͨFat Binary
    • lipoίϚϯυͰ݁߹͢Δ
    • UIKit for Mac΋CPUΞʔΩςΫνϟ͸x86_64
    • 1ͭͷFat BinaryͰ͸iOS SimulatorͱUIKit for MacΛڞଘͤ͞ΒΕͳ͍
    • ඞવతʹ෼཭͢Δඞཁ͕͋Δ

    View full-size slide

  13. XCFrameworks
    UIKit for Mac
    • ϓϥοτϑΥʔϜຖʹframework͕෼཭͞Ε͍ͯΔ
    • carthage copy-frameworks͕ෆཁʹͳΔՄೳੑ
    • ετΞਃ੥࣌ʹ͸xcframeworkͷத͔ΒɺiOS Device༻ͷ
    framework͕ຒΊࠐ·ΕΔʢiOS Simulatorͷ෼͸ຒΊࠐ·Εͳ͍ʣ
    • ετΞਃ੥༻ͷFat Binary͔ΒSimulatorͷCPUΞʔΩςΫνϟΛ
    औΓআ͘ඞཁ͕ͳ͘ͳΔ

    View full-size slide

  14. Ϗϧυͷ࿩͸লུ
    • Build Settings
    • "Build Libraries for Distribution"
    • "Supports UIKit for Mac"
    • "Derive UIKit for Mac Product Bundle Identifier"
    • xcodebuild archive: Multiple Destinations including Simulator
    xcodebuild archive \
    -scheme FooBarBaz
    -destination ... \
    -destination ... \
    -destination ...

    View full-size slide

  15. Creating XCFrameworks
    $ xcodebuild -create-framework \
    -framework iphonesimulator/Himotoki.framework \
    -framework iphoneos/Himotoki.framework \
    -framework uikitformac/Himotoki.framework \
    -output Himotoki.xcframework

    View full-size slide

  16. XCFrameworks: Directory
    Structure
    Himotoki.xcframework
    ├── Info.plist
    ├── ios-armv7_arm64
    │ └── Himotoki.framework
    ├── ios-i386_x86_64-simulator
    │ └── Himotoki.framework
    └── ios-x86_64-uikitformac
    └── Himotoki.framework

    View full-size slide

  17. XCFrameworks: Info.plist
    ?xml version="1.0" encoding="UTF-8"?>



    AvailableLibraries


    LibraryIdentifier
    ios-x86_64-uikitformac
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    uikitformac


    LibraryIdentifier
    ios-armv7_arm64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    armv7
    arm64

    SupportedPlatform
    ios


    LibraryIdentifier
    ios-i386_x86_64-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    i386
    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    simulator


    CFBundlePackageType
    XFWK
    XCFrameworkFormatVersion
    1.0


    View full-size slide


  18. AvailableLibraries


    LibraryIdentifier
    ios-x86_64-uikitformac
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    uikitformac

    View full-size slide


  19. LibraryIdentifier
    ios-armv7_arm64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    armv7
    arm64

    SupportedPlatform
    ios

    View full-size slide


  20. LibraryIdentifier
    ios-i386_x86_64-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    i386
    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    simulator

    View full-size slide


  21. CFBundlePackageType
    XFWK
    XCFrameworkFormatVersion
    1.0


    View full-size slide

  22. xcodebuild -create-xcframework
    $ xcodebuild -create-xcframework -help
    OVERVIEW: Utility for packaging multiple build configurations of a given library or framework into a single xcframework.
    USAGE:
    xcodebuild -create-xcframework -framework [-framework ...] -output
    xcodebuild -create-xcframework -library [-headers ] [-library [-headers ]...] -output
    OPTIONS:
    -framework Adds a framework from the given .
    -library Adds a static or dynamic library from the given .
    -headers Adds the headers from the given . Only applicable with -library.
    -output The to write the xcframework to.
    -help Show this help content.

    View full-size slide

  23. !
    ࠓޙͷ֤छπʔϧ΍SDKͰͷαϙʔτʹظ଴

    View full-size slide

  24. !
    Happy Package Life

    View full-size slide

  25. Thank you
    Sho Ikeda / @ikesyo

    View full-size slide