Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Swift Packages

Slide 4

Slide 4 text

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, ...

Slide 5

Slide 5 text

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΁ͷ౷߹ͷ෍ੴ

Slide 6

Slide 6 text

// 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] )

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

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ͷඞཁੑ͕ബΕͨ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

XCFrameworks

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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Λڞଘͤ͞ΒΕͳ͍ • ඞવతʹ෼཭͢Δඞཁ͕͋Δ

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Ϗϧυͷ࿩͸লུ • 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 ...

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

AvailableLibraries LibraryIdentifier ios-x86_64-uikitformac LibraryPath Himotoki.framework SupportedArchitectures x86_64 SupportedPlatform ios SupportedPlatformVariant uikitformac

Slide 21

Slide 21 text

LibraryIdentifier ios-armv7_arm64 LibraryPath Himotoki.framework SupportedArchitectures armv7 arm64 SupportedPlatform ios

Slide 22

Slide 22 text

LibraryIdentifier ios-i386_x86_64-simulator LibraryPath Himotoki.framework SupportedArchitectures i386 x86_64 SupportedPlatform ios SupportedPlatformVariant simulator

Slide 23

Slide 23 text

CFBundlePackageType XFWK XCFrameworkFormatVersion 1.0

Slide 24

Slide 24 text

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.

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

! Happy Package Life

Slide 27

Slide 27 text

Thank you Sho Ikeda / @ikesyo