Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Command Line Tool in swift

8,343 views

Published on

potatotips #20

Published in: Engineering
  • Be the first to comment

Command Line Tool in swift

  1. 1. Command Line Tool in Swift Mercari Inc. @kitasuke
  2. 2. CLI tool or script might be needed for pre-action before build
  3. 3. Why using Swift?
  4. 4. First step to use Swift in your project
  5. 5. CLI tool, not Script 4 dependency management 4 flexible extension
  6. 6. How developing with Xcode?
  7. 7. References Carthage, SwiftCov
  8. 8. Framework Commandant is a Swift framework for parsing command-line arguments
  9. 9. Project directory 4 Carthage 4 xcodeproj 4 xcworkspace 4 Makefile 4 script
  10. 10. Workspace structure 4 Main target 4 Static framework target 4 Test target 4 xcconfigs 4 framework projects
  11. 11. Configurations
  12. 12. Create a project
  13. 13. Clean up files and add main.swift
  14. 14. Add a framework
  15. 15. Run Carthage carthage update --use-submodules github "Carthage/Commandant" github "jspahrsummers/xcconfigs" github "ishkawa/APIKit" github "ikesyo/Himotoki"
  16. 16. Set xcconfigs
  17. 17. Run bootstrap script objc-build-scripts: standardize how Objective-C projects are bootstrapped after cloning
  18. 18. New workspace Add all the projects into here
  19. 19. Add frameworks General → Linked Frameworks and Libraries
  20. 20. Copy frameworks in Build Phrases Destination is frameworks
  21. 21. Runpath in Buld Settings for main target /Library/Frameworks/***.framework/ Versions/Current/Frameworks/
  22. 22. Embedded Content Contains Swift Code for framework target Set to YES, default is NO
  23. 23. Add components.plist for pkgbuild command <plist version="1.0"> <array> <dict> <key>BundleIsVersionChecked</key> <false/> <key>BundleOverwriteAction</key> <string>upgrade</string> <key>ChildBundles</key> <array> <dict> <key>BundleOverwriteAction</key> <string></string> <key>RootRelativeBundlePath</key> <string>Library/Frameworks/***.framework/Versions/A/Frameworks/***.framework</string> </dict> </array> <key>RootRelativeBundlePath</key> <string>Library/Frameworks/***.framework</string> </dict> </array> </plist>
  24. 24. Run install command pkgbuild --component-plist --identifier --install-location --root --version
  25. 25. Adding command
  26. 26. Using Commandant public protocol CommandType { typealias ClientError /// The action that users should specify to use this subcommand (e.g., /// `help`). var verb: String { get } /// A human-readable, high-level description of what this command is used /// for. var function: String { get } /// Runs this subcommand in the given mode. func run(mode: CommandMode) -> Result<(), CommandantError<ClientError>> }
  27. 27. Debugging
  28. 28. Arguments Passed on Launch in scheme setting
  29. 29. Demo
  30. 30. Start your Swift life from now !
  31. 31. Thank you

×