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 Package Manager V4Ͱ
    Alfred WorkflowΛ࡞Ζ͏
    iOSษڧձ 2017/10/16
    satoshin21

    View full-size slide

  2. Agenda
    • Swift Package Manager V4جૅ
    • Alfred Workflow with SwiftPM V4
    • ͦͷଞ

    View full-size slide

  3. Swift Package Manager

    View full-size slide

  4. Swift Package Manager
    • Appleͷఏڙ͢ΔύοέʔδϚωʔδϟ
    • like CocoaPods, Carthage
    • ࠓͷͱ͜ΖɺαʔόαΠυ΍CLIπʔϧʹಛԽ

    View full-size slide

  5. ؀ڥ
    $ swift --version
    > Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
    > Target: x86_64-apple-macosx10.9

    View full-size slide

  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/

    View full-size slide

  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!

    View full-size slide

  8. Files / Dirs
    • Package.swift
    • ґଘؔ܎΍ύοέʔδ໊Λఆٛ͢ΔϚχϑΣετϑΝΠϧ
    • Sources/
    • ιʔεɾϑΝΠϧΛ֨ೲ
    • αϒσΟϨΫτϦ͕TargetͱͳΔ

    View full-size slide

  9. Files / Dirs
    • Tests/
    • TestϑΝΠϧΛ֨ೲ
    • αϒσΟϨΫτϦ͕testTargetͱͳΔ
    • --type libraryͷΈ testTarget͕ࣗಈతʹ࡞੒͞ΕΔ

    View full-size slide

  10. package init --type
    • executable
    • CLI͔Β࣮ߦՄೳͳόΠφϦΛϏϧυՄೳ
    • library
    • executable, libraryͳͲ͔ΒґଘՄೳ
    • empty
    • system-module

    View full-size slide

  11. Package.swift
    • ґଘؔ܎ఆٛϑΝΠϧ
    • Podfile, Cartfile, Gemfile...

    View full-size slide

  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: []),
    ]
    )

    View full-size slide

  13. Swift.package swift-tools-version
    // swift-tools-version:4.0
    • 1ߦ໨ʹఆٛ
    • ࢦఆ͠ͳ͍৔߹ɺswift-tools-version:3.1.0ͱͳΔ

    View full-size slide

  14. Swift.Package targets, products
    • products
    • library or executable
    • ֎෦͔ΒࢀরՄೳ
    • targets
    • target or testTarget
    • Ϟδϡʔϧ΍ςετεΠʔτΛఆٛ

    View full-size slide

  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"]),
    ]
    )

    View full-size slide

  16. 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"))
    }

    View full-size slide

  17. Alfred WorkflowΛ࡞Δ

    View full-size slide

  18. Alfred
    • ࠷ڧϥϯνϟʔ
    • ΞϓϦىಈ͔ΒWebݕࡧɺiTunesͷૢ
    ࡞·ͰσϑΥϧτͰՄೳ
    • ϑϦʔ΢ΣΞ͕ͩɺPower PackΛߪೖ
    ͢ΔࣄͰ֮੧͢Δ
    • (ଟ෼)όοτϚϯͷ(͔͍͍ͬ͜)ࣥࣄ͔
    Β໊લ͕͖ͯΔ

    View full-size slide

  19. Alfred Workflow
    • Power PackΛߪೖ͢ΔࣄͰར༻Ͱ͖Δ
    • ϗοτΩʔɺ΋͘͠͸ΩʔϫʔυΛࢦఆͯ͠εΫϦϓτΛ࣮ߦ
    • SwiftͰ΋࡞ΕΔʂ

    View full-size slide

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

    View full-size slide

  21. Alfred WorkflowΛ࡞੒
    • Alfred Preferences͔ΒworkflowΛબ୒

    View full-size slide

  22. 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"]),
    ]
    )

    View full-size slide

  23. SwiftPM Tips - testTarget
    • main.swiftΛϞδϡʔϧͷςετ͕Ͱ͖ͳ͍ͷෆ۩߹(ͱ͍͏͔
    ࢓༷)͕͋Δ (SR-1503)
    • Linux؀ڥԼͷ৔߹ɺObjective-CϥϯλΠϜͰಈ͘XCTest͕ଘࡏ
    ͤͣɺTest༻ͷmain.swift(࣮ߦϑΝΠϧ)͕ඞཁʹͳΔ
    • executableͷmain.swiftͱόοςΟϯά͢Δҝʁ
    • testίʔυΛॻ͘৔߹ɺlibraryͱͯ͠ϏδωεϩδοΫΛ੾Γग़
    ͯ͠ɺtestTargetΛผʹࢦఆͨ͠ํ͕ૉ௚ʹಈ͘

    View full-size slide

  24. Editable Packages
    $ swift package edit AlfredKit
    • ґଘઌͷύοέʔδΛ /PackagesσΟϨΫτϦҎԼʹ֨ೲ
    • libraryͱexecutableΛಉ࣌ʹฤू͢Δ৔߹ʹศར
    • Packages/ҎԼ͕༏ઌͯ͠ίϯύΠϧ͞ΕΔҝɺ஫ҙ

    View full-size slide