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

Swift Package Manager V4でAlfred Workflowを作ろう

F05557f473bac91b5bdc6c2e8a95c6f2?s=47 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

F05557f473bac91b5bdc6c2e8a95c6f2?s=128

satoshin21

October 16, 2017
Tweet

Transcript

  1. Swift Package Manager V4Ͱ Alfred WorkflowΛ࡞Ζ͏ iOSษڧձ 2017/10/16 satoshin21

  2. Agenda • Swift Package Manager V4جૅ • Alfred Workflow with

    SwiftPM V4 • ͦͷଞ
  3. Swift Package Manager

  4. Swift Package Manager • Appleͷఏڙ͢ΔύοέʔδϚωʔδϟ • like CocoaPods, Carthage •

    ࠓͷͱ͜ΖɺαʔόαΠυ΍CLIπʔϧʹಛԽ
  5. ؀ڥ $ swift --version > Apple Swift version 4.0 (swiftlang-900.0.65

    clang-900.0.37) > Target: x86_64-apple-macosx10.9
  6. 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/
  7. 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!
  8. Files / Dirs • Package.swift • ґଘؔ܎΍ύοέʔδ໊Λఆٛ͢ΔϚχϑΣετϑΝΠϧ • Sources/ •

    ιʔεɾϑΝΠϧΛ֨ೲ • αϒσΟϨΫτϦ͕TargetͱͳΔ
  9. Files / Dirs • Tests/ • TestϑΝΠϧΛ֨ೲ • αϒσΟϨΫτϦ͕testTargetͱͳΔ •

    --type libraryͷΈ testTarget͕ࣗಈతʹ࡞੒͞ΕΔ
  10. package init --type • executable • CLI͔Β࣮ߦՄೳͳόΠφϦΛϏϧυՄೳ • library •

    executable, libraryͳͲ͔ΒґଘՄೳ • empty • system-module
  11. Package.swift • ґଘؔ܎ఆٛϑΝΠϧ • Podfile, Cartfile, Gemfile...

  12. 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: []), ] )
  13. Swift.package swift-tools-version // swift-tools-version:4.0 • 1ߦ໨ʹఆٛ • ࢦఆ͠ͳ͍৔߹ɺswift-tools-version:3.1.0ͱͳΔ

  14. Swift.Package targets, products • products • library or executable •

    ֎෦͔ΒࢀরՄೳ • targets • target or testTarget • Ϟδϡʔϧ΍ςετεΠʔτΛఆٛ
  15. 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"]), ] )
  16. Package.Dependency • ґଘύοέʔδΛఆٛ dependencies: [ // `from`ͰVersionࢦఆ(Version͸tagͰࢦఆ͢Δ) .package(url: "git@github.com...", from:

    "1.0.0") .package(url: "git@github.com...", from: .init(1, 0, 0)) // Rangeࢦఆ .package(url: "git@github.com...", "1.0.0"..<"2.0.0") // ϒϥϯνɺϦϏδϣϯ౳ࢦఆՄೳ .package(url: "git@github.com...", .branch("develop")) .package(url: "git@github.com...", .revision("8b4975a")) }
  17. Alfred WorkflowΛ࡞Δ

  18. Alfred • ࠷ڧϥϯνϟʔ • ΞϓϦىಈ͔ΒWebݕࡧɺiTunesͷૢ ࡞·ͰσϑΥϧτͰՄೳ • ϑϦʔ΢ΣΞ͕ͩɺPower PackΛߪೖ ͢ΔࣄͰ֮੧͢Δ

    • (ଟ෼)όοτϚϯͷ(͔͍͍ͬ͜)ࣥࣄ͔ Β໊લ͕͖ͯΔ
  19. Alfred Workflow • Power PackΛߪೖ͢ΔࣄͰར༻Ͱ͖Δ • ϗοτΩʔɺ΋͘͠͸ΩʔϫʔυΛࢦఆͯ͠εΫϦϓτΛ࣮ߦ • SwiftͰ΋࡞ΕΔʂ

  20. ࠓճ࡞ͬͨαϯϓϧ • https://github.com/satoshin21/GitHubWorkflow • executable • APIKitͰϦϙδτϦΛݕࡧ • AlfredKitΛ࢖ͬͯScript FilterΛexport

    • https://github.com/satoshin21/AlfredKit • library
  21. Alfred WorkflowΛ࡞੒ • Alfred Preferences͔ΒworkflowΛબ୒

  22. Package.swift // swift-tools-version:4.0 import PackageDescription let package = Package( name:

    "GitHubSearch", dependencies: [ // AlfredKitͱAPIKitΛґଘؔ܎ͱͯ͠ఆٛ .package(url: "git@github.com:satoshin21/AlfredKit", from: "0.1.0"), .package(url: "git@github.com:ishkawa/APIKit.git", from: "3.1.2") ], targets: [ // targetʹґଘઌͷPackageΛࢦఆ .target( name: "GitHubSearch", dependencies: ["AlfredKit", "APIKit"]), ] )
  23. DEMO

  24. SwiftPM Tips - testTarget • main.swiftΛϞδϡʔϧͷςετ͕Ͱ͖ͳ͍ͷෆ۩߹(ͱ͍͏͔ ࢓༷)͕͋Δ (SR-1503) • Linux؀ڥԼͷ৔߹ɺObjective-CϥϯλΠϜͰಈ͘XCTest͕ଘࡏ

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

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