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 #ؔϞό
  2. Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ •

    εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo
  3. 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, ...
  4. // 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] )
  5. 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ͷඞཁੑ͕ബΕͨ
  6. Swift Packages: Known Issues • 1ͭͷλʔήοτͰSwiftͱCɺSwiftͱObjective-Cɺͱ͍͏ࠞͥํ͸Ͱ͖ͳ͍ • λʔήοτΛ෼͚Δඞཁ͕͋Δ • Ϧιʔε͕࣋ͯͳ͍

    • ը૾, Ի੠, Storyboard, ϩʔΧϥΠζ༻จࣈྻ, ... • όΠφϦ഑෍͸Ͱ͖ͳ͍ • Package.swiftʹͦ͏͍͏λʔήοτఆٛ͸ͳ͍ • UIܥͷϥΠϒϥϦʔ΍֤छSDKͰ͸ɺCarthage΍CocoaPods͸·݈ͩࡏͰ͸ͳ͍ ͔
  7. 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
  8. 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Λڞଘͤ͞ΒΕͳ͍ • ඞવతʹ෼཭͢Δඞཁ͕͋Δ
  9. XCFrameworks UIKit for Mac • ϓϥοτϑΥʔϜຖʹframework͕෼཭͞Ε͍ͯΔ • carthage copy-frameworks͕ෆཁʹͳΔՄೳੑ •

    ετΞਃ੥࣌ʹ͸xcframeworkͷத͔ΒɺiOS Device༻ͷ framework͕ຒΊࠐ·ΕΔʢiOS Simulatorͷ෼͸ຒΊࠐ·Εͳ͍ʣ • ετΞਃ੥༻ͷFat Binary͔ΒSimulatorͷCPUΞʔΩςΫνϟΛ औΓআ͘ඞཁ͕ͳ͘ͳΔ
  10. Ϗϧυͷ࿩͸লུ • 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 ...
  11. Creating XCFrameworks $ xcodebuild -create-framework \ -framework iphonesimulator/Himotoki.framework \ -framework

    iphoneos/Himotoki.framework \ -framework uikitformac/Himotoki.framework \ -output Himotoki.xcframework
  12. 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
  13. XCFrameworks: Info.plist ?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST

    1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>AvailableLibraries</key> <array> <dict> <key>LibraryIdentifier</key> <string>ios-x86_64-uikitformac</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>uikitformac</string> </dict> <dict> <key>LibraryIdentifier</key> <string>ios-armv7_arm64</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>armv7</string> <string>arm64</string> </array> <key>SupportedPlatform</key> <string>ios</string> </dict> <dict> <key>LibraryIdentifier</key> <string>ios-i386_x86_64-simulator</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>i386</string> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>simulator</string> </dict> </array> <key>CFBundlePackageType</key> <string>XFWK</string> <key>XCFrameworkFormatVersion</key> <string>1.0</string> </dict> </plist>
  14. <dict> <key>AvailableLibraries</key> <array> <dict> <key>LibraryIdentifier</key> <string>ios-x86_64-uikitformac</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array>

    <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>uikitformac</string> </dict>
  15. 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 <path> [-framework <path>...] -output <path> xcodebuild -create-xcframework -library <path> [-headers <path>] [-library <path> [-headers <path>]...] -output <path> OPTIONS: -framework <path> Adds a framework from the given <path>. -library <path> Adds a static or dynamic library from the given <path>. -headers <path> Adds the headers from the given <path>. Only applicable with -library. -output <path> The <path> to write the xcframework to. -help Show this help content.