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

Swift Package Manager V4でAlfred Workflowを作ろう

satoshin21
October 16, 2017

Swift Package Manager V4でAlfred Workflowを作ろう

iOS社内勉強会 @eureka, Inc.

Samples:

GitHubWorkflow
https://github.com/satoshin21/GitHubWorkflow
AlfredKit
https://github.com/satoshin21/AlfredKit

satoshin21

October 16, 2017
Tweet

More Decks by satoshin21

Other Decks in Technology

Transcript

  1. ؀ڥ $ swift --version > Apple Swift version 4.0 (swiftlang-900.0.65

    clang-900.0.37) > Target: x86_64-apple-macosx10.9
  2. Hello World - init $ mkdir MyFirstPackage $ cd MyFirstPackage/

    $ swift package init --type executable > Creating executable package: MyFirstPackage > Creating Package.swift > Creating README.md > Creating .gitignore > Creating Sources/ > Creating Sources/MyFirstPackage/main.swift > Creating Tests/
  3. Hello World - build $ swift build Compile Swift Module

    'MyFirstPackage' (1 sources) Linking ./.build/x86_64-apple-macosx10.10/debug/MyFirstPackage $ swift run # or .build/debug/MyFirstPackage Hello, world!
  4. package init --type • executable • CLI͔Β࣮ߦՄೳͳόΠφϦΛϏϧυՄೳ • library •

    executable, libraryͳͲ͔ΒґଘՄೳ • empty • system-module
  5. Package.swift // swift-tools-version:4.0 import PackageDescription let package = Package( name:

    "MyFirstPackage", dependencies: [ // .package(url: /* package url */, from: "1.0.0"), ], targets: [ .target( name: "MyFirstPackage", dependencies: []), ] )
  6. Swift.Package targets, products • products • library or executable •

    ֎෦͔ΒࢀরՄೳ • targets • target or testTarget • Ϟδϡʔϧ΍ςετεΠʔτΛఆٛ
  7. Swift.Package targets, products let package = Package( name: "AlfredKit", products:

    [ .library( name: "AlfredKit", targets: ["AlfredKit"]), ], targets: [ .target( name: "AlfredKit", dependencies: []), .testTarget( name: "AlfredKitTests", dependencies: ["AlfredKit"]), ] )
  8. Package.Dependency • ґଘύοέʔδΛఆٛ dependencies: [ // `from`ͰVersionࢦఆ(Version͸tagͰࢦఆ͢Δ) .package(url: "[email protected]...", from:

    "1.0.0") .package(url: "[email protected]...", from: .init(1, 0, 0)) // Rangeࢦఆ .package(url: "[email protected]...", "1.0.0"..<"2.0.0") // ϒϥϯνɺϦϏδϣϯ౳ࢦఆՄೳ .package(url: "[email protected]...", .branch("develop")) .package(url: "[email protected]...", .revision("8b4975a")) }
  9. Package.swift // swift-tools-version:4.0 import PackageDescription let package = Package( name:

    "GitHubSearch", dependencies: [ // AlfredKitͱAPIKitΛґଘؔ܎ͱͯ͠ఆٛ .package(url: "[email protected]:satoshin21/AlfredKit", from: "0.1.0"), .package(url: "[email protected]:ishkawa/APIKit.git", from: "3.1.2") ], targets: [ // targetʹґଘઌͷPackageΛࢦఆ .target( name: "GitHubSearch", dependencies: ["AlfredKit", "APIKit"]), ] )
  10. SwiftPM Tips - testTarget • main.swiftΛϞδϡʔϧͷςετ͕Ͱ͖ͳ͍ͷෆ۩߹(ͱ͍͏͔ ࢓༷)͕͋Δ (SR-1503) • Linux؀ڥԼͷ৔߹ɺObjective-CϥϯλΠϜͰಈ͘XCTest͕ଘࡏ

    ͤͣɺTest༻ͷmain.swift(࣮ߦϑΝΠϧ)͕ඞཁʹͳΔ • executableͷmain.swiftͱόοςΟϯά͢Δҝʁ • testίʔυΛॻ͘৔߹ɺlibraryͱͯ͠ϏδωεϩδοΫΛ੾Γग़ ͯ͠ɺtestTargetΛผʹࢦఆͨ͠ํ͕ૉ௚ʹಈ͘
  11. Editable Packages $ swift package edit AlfredKit • ґଘઌͷύοέʔδΛ /PackagesσΟϨΫτϦҎԼʹ֨ೲ

    • libraryͱexecutableΛಉ࣌ʹฤू͢Δ৔߹ʹศར • Packages/ҎԼ͕༏ઌͯ͠ίϯύΠϧ͞ΕΔҝɺ஫ҙ
  12. END