Share
Embed
Transcript
27 slides
-
Swift Packages and XCFrameworks in Xcode 11 Sho Ikeda /
@ikesyo ؼ͖ͬͯͨؔϞόΠϧΞϓϦݚڀձ#2 2019-06-12 Wed #ؔϞό -
Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗా ᠳ • ͯͳ@ژ •
εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo -
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, ... -
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ͷ౷߹ͷੴ -
// 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] ) -
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ͷඞཁੑ͕ബΕͨ -
Swift Packages: Known Issues • 1ͭͷλʔήοτͰSwiftͱCɺSwiftͱObjective-Cɺͱ͍͏ࠞͥํͰ͖ͳ͍ • λʔήοτΛ͚Δඞཁ͕͋Δ • Ϧιʔε͕࣋ͯͳ͍
• ը૾, Ի, Storyboard, ϩʔΧϥΠζ༻จࣈྻ, ... • όΠφϦͰ͖ͳ͍ • Package.swiftʹͦ͏͍͏λʔήοτఆٛͳ͍ • UIܥͷϥΠϒϥϦʔ֤छSDKͰɺCarthageCocoaPods·݈ͩࡏͰͳ͍ ͔ -
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 -
XCFrameworks UIKit for Mac • ͜Ε·ͰͷόΠφϦ • iOS Deviceͷarmv7ͱarm64ɺiOS Simulatorͷx86_64ʢͱi386ʣΛ1ͭʹ·ͱ
ΊͨFat Binary • lipoίϚϯυͰ݁߹͢Δ • UIKit for MacCPUΞʔΩςΫνϟx86_64 • 1ͭͷFat BinaryͰiOS SimulatorͱUIKit for MacΛڞଘͤ͞ΒΕͳ͍ • ඞવతʹ͢Δඞཁ͕͋Δ -
XCFrameworks UIKit for Mac • ϓϥοτϑΥʔϜຖʹframework͕͞Ε͍ͯΔ • carthage copy-frameworks͕ෆཁʹͳΔՄೳੑ •
ετΞਃ࣌ʹxcframeworkͷத͔ΒɺiOS Device༻ͷ framework͕ຒΊࠐ·ΕΔʢiOS SimulatorͷຒΊࠐ·Εͳ͍ʣ • ετΞਃ༻ͷFat Binary͔ΒSimulatorͷCPUΞʔΩςΫνϟΛ औΓআ͘ඞཁ͕ͳ͘ͳΔ -
Ϗϧυͷলུ • 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 ... -
Creating XCFrameworks $ xcodebuild -create-framework \ -framework iphonesimulator/Himotoki.framework \ -framework
iphoneos/Himotoki.framework \ -framework uikitformac/Himotoki.framework \ -output Himotoki.xcframework -
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 -
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> -
<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> -
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.