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

Making iOS Development Efficient with Swift

Making iOS Development Efficient with Swift

Satoshi Hachiya

July 15, 2017
Tweet

More Decks by Satoshi Hachiya

Other Decks in Programming

Transcript

  1. Satoshi Hachiya • Japanese iOS developer at ookami, Inc. •

    Making an iOS application, Player! • Organizer of try! Swift • Tokyo, NYC, India
  2. Satoshi Hachiya • Japanese iOS developer at ookami, Inc. •

    Making an iOS application, Player! • Organizer of try! Swift • Tokyo, NYC, India • Founder of Pancake Meetup • Tokyo, San Jose...
  3. Agenda • Using the REPL • What is the REPL?

    • Using the Swift Package Manager • What is the Swift Package Manager?
  4. Agenda • Using the REPL • What is the REPL?

    • Using the Swift Package Manager • What is the Swift Package Manager? • Aproaching to the practical use
  5. Changing Swift Version on the Terminal • Xcode 8.3 includes

    Swift 3.1 • Xcode 9 beta includes Swift 4 Typing $ export DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer
  6. On the Terminal Typing $ swift Result Welcome to Apple

    Swift version 4.0 (swiftlang-900.0.49.1 clang-900.0.29). Type :help for assistance. 1>
  7. Result 1> let country = "Belarus" country: String = "Belarus"

    2> print("Hello, \(country)!") Hello, Belarus!
  8. Multiple Lines 1> let world = ["Belarus", "Minsk"] world: [String]

    = 2 values { [0] = "Belarus" [1] = "Minsk" } 2> world.forEach { 3. print("Hello, \($0)!") 4. } Hello, Belarus! Hello, Minsk!
  9. Result 1> import Darwin 2> let cwd = getcwd(nil, Int(PATH_MAX))

    cwd: UnsafeMutablePointer<Int8>? = 0x0000000100800000
  10. Typing 1> import Darwin 2> let cwd = getcwd(nil, Int(PATH_MAX))

    cwd: UnsafeMutablePointer<Int8>? = 0x0000000100800000 3> let path = String(validatingUTF8: cwd!)
  11. Result 1> import Darwin 2> let cwd = getcwd(nil, Int(PATH_MAX))

    cwd: UnsafeMutablePointer<Int8>? = 0x0000000100800000 3> let path = String(validatingUTF8: cwd!) path: String? = "/Users/CommandLineTool"
  12. Result OVERVIEW: Swift compiler USAGE: swift [options] <inputs> OPTIONS: -assert-config

    <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Unchecked, DisableReplacement. -continue-building-after-errors Continue building, even after errors are encountered -D <value> Marks a conditional compilation flag as true -enforce-exclusivity=<enforcement> Enforce law of exclusivity -framework <value> Specifies a framework which should be linked against -Fsystem <value> Add directory to system framework search path -F <value> Add directory to framework search path -gdwarf-types Emit full DWARF type info. -gline-tables-only Emit minimal debug info for backtraces only -gnone Don't emit debug info -g Emit debug info. This is the preferred setting for debugging with LLDB. -help Display available options -index-store-path <path> Store indexing data to <path> -I <value> Add directory to the import search path -j <n> Number of commands to execute in parallel -L <value> Add directory to library link search path -l<value> Specifies a library which should be linked against -module-cache-path <value> Specifies the Clang module cache path -module-link-name <value> Library to link against when using this module -module-name <value> Name of the module to build -nostdimport Don't search the standard library import path for modules -num-threads <n> Enable multi-threading and specify number of threads -Onone Compile without any optimization -Ounchecked Compile with optimizations and remove runtime safety checks -O Compile with optimizations -sdk <sdk> Compile against <sdk> -static-executable Statically link the executable -static-stdlib Statically link the Swift standard library -suppress-warnings Suppress all warnings -swift-version <vers> Interpret input according to a specific Swift language version number -target-cpu <value> Generate code for a particular CPU variant -target <value> Generate code for the given target -use-ld=<value> Specifies the linker to be used -version Print version information and exit -v Show commands to run and use verbose output -warn-swift3-objc-inference-complete Warn about deprecated @objc inference in Swift 3 for every declaration that will no longer be inferred as @objc in Swift 4 -warn-swift3-objc-inference-minimal Warn about deprecated @objc inference in Swift 3 based on direct uses of the Objective-C entrypoint -warnings-as-errors Treat warnings as errors -Xcc <arg> Pass <arg> to the C/C++/Objective-C compiler -Xlinker <value> Specifies an option which should be passed to the linker
  13. Result OVERVIEW: Perform operations on Swift packages USAGE: swift package

    [options] subcommand OPTIONS: --build-path Specify build/cache directory [default: ./.build] --configuration, -c Build with configuration (debug|release) [default: debug] --disable-prefetching --disable-sandbox Disable using the sandbox when executing subprocesses --enable-prefetching --package-path Change working directory before any other operation --verbose, -v Increase verbosity of informational output -Xcc Pass flag through to all C compiler invocations -Xlinker Pass flag through to all linker invocations -Xswiftc Pass flag through to all Swift compiler invocations --help Display available options SUBCOMMANDS: clean Delete build artifacts describe Describe the current package dump-package Print parsed Package.swift as JSON edit Put a package in editable mode generate-xcodeproj Generates an Xcode project init Initialize a new package reset Reset the complete cache/build directory resolve Resolve package dependencies show-dependencies Print the resolved dependency graph tools-version Manipulate tools version of the current package unedit Remove a package from editable mode update Update package dependencies
  14. Result OVERVIEW: Build sources into binary products USAGE: swift build

    [options] OPTIONS: --build-path Specify build/cache directory [default: ./.build] --build-tests Build the both source and test targets --configuration, -c Build with configuration (debug|release) [default: debug] --disable-prefetching --disable-sandbox Disable using the sandbox when executing subprocesses --enable-prefetching --package-path Change working directory before any other operation --verbose, -v Increase verbosity of informational output -Xcc Pass flag through to all C compiler invocations -Xlinker Pass flag through to all linker invocations -Xswiftc Pass flag through to all Swift compiler invocations --help Display available options
  15. Result OVERVIEW: Build and run tests USAGE: swift test [options]

    OPTIONS: --build-path Specify build/cache directory [default: ./.build] --configuration, -c Build with configuration (debug|release) [default: debug] --disable-prefetching --disable-sandbox Disable using the sandbox when executing subprocesses --enable-prefetching --filter Run test cases matching regular expression, Format: <test-target>.<test-case> or <test-target>.<test-case>/<test> --list-tests, -l Lists test methods in specifier format --package-path Change working directory before any other operation --parallel Run the tests in parallel. --skip-build Skip building the test target --verbose, -v Increase verbosity of informational output -Xcc Pass flag through to all C compiler invocations -Xlinker Pass flag through to all linker invocations -Xswiftc Pass flag through to all Swift compiler invocations --help Display available options
  16. Swift Evolution https:/ /github.com/apple/swift-evolution/blob/master/proposals/ 0179-swift-run-command.md OVERVIEW: Build and run executable

    USAGE: swift run [options] [executable [arguments]] OPTIONS: --build-path Specify build/cache directory [default: ./.build] --chdir, -C Change working directory before any other operation --color Specify color mode (auto|always|never) [default: auto] --configuration, -c Build with configuration (debug|release) [default: debug] --enable-prefetching Enable prefetching in resolver --skip-build Skip building the executable product --verbose, -v Increase verbosity of informational output -Xcc Pass flag through to all C compiler invocations -Xlinker Pass flag through to all linker invocations -Xswiftc Pass flag through to all Swift compiler invocations --help Display available options
  17. Result Swift 4 Creating executable package: CommandLineTool Creating Package.swift Creating

    README.md Creating .gitignore Creating Sources/ Creating Sources/CommandLineTool/main.swift Creating Tests/
  18. Result Swift 3.1 Creating executable package: CommandLineTool Creating Package.swift Creating

    .gitignore Creating Sources/ Creating Sources/main.swift Creating Tests/
  19. Package.swift import PackageDescription let package = Package( name: "CommandLineTool", dependencies:

    [], targets: [ .target( name: "CommandLineTool", dependencies: []), ] )
  20. Example Importing Module • Importing Darwin • For linux, import

    Glibc • Getting the path of the current woriking directory
  21. main.swift #if os(Linux) import Glibc #else import Darwin #endif if

    let cwd = getcwd(nil, Int(PATH_MAX)), let path = String(validatingUTF8: cwd) { print("\(path)") }
  22. Package.swift import PackageDescription let package = Package( name: "CommandLineTool", dependencies:

    [ .package(url: "https://github.com/kylef/Commander.git", from: "0.1.0"), ], targets: [ .target( name: "CommandLineTool", dependencies: ["Commander"]), ] )
  23. Result Fetching https://github.com/kylef/Commander.git Fetching https://github.com/kylef/Spectre.git Cloning https://github.com/kylef/Spectre.git Resolving https://github.com/kylef/Spectre.git at

    0.7.2 Cloning https://github.com/kylef/Commander.git Resolving https://github.com/kylef/Commander.git at 0.6.1 Compile Swift Module 'CommandLineTool' (1 sources) Linking ./.build/debug/CommandLineTool
  24. Result Fetching https://github.com/kylef/Commander.git Fetching https://github.com/kylef/Spectre.git Cloning https://github.com/kylef/Spectre.git Resolving https://github.com/kylef/Spectre.git at

    0.7.2 Cloning https://github.com/kylef/Commander.git Resolving https://github.com/kylef/Commander.git at 0.6.1 Compile Swift Module 'CommandLineTool' (1 sources) Linking ./.build/release/CommandLineTool
  25. https:/ /github.com/mono0926/ LicensePlist • A command line tool building via

    the Swift Package Manager • A license list generator of all your dependencies for iOS applications
  26. Package.swift import PackageDescription let package = Package( name: "LicensePlist", targets:

    [ Target(name: "LicensePlist", dependencies: ["LicensePlistCore"]), Target(name: "LicensePlistCore") ], dependencies: [ .Package(url: "https://github.com/kylef/Commander.git", majorVersion: 0), .Package(url: "https://github.com/ikesyo/Himotoki.git", majorVersion: 3), .Package(url: "https://github.com/ishkawa/APIKit.git", majorVersion: 3), .Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1), .Package(url: "https://github.com/behrang/YamlSwift.git", majorVersion: 3) ] )
  27. Conclusion • Using the REPL • Using the Swift Package

    Manager • Aproaching to the practical use
  28. Conclusion • Using the REPL • Using the Swift Package

    Manager • Aproaching to the practical use My Issue Migration my command line tools to Swift 4 • https:/ /github.com/tryswift/tryswiftdev
  29. My Issue Migration my command line tools to Swift 4

    • https:/ /github.com/tryswift/tryswiftdev • Downloading Swift snapshot file • README Generator • etc.
  30. Reference • Swift.org Mailing list • https:/ /lists.swift.org/pipermail/swift-build-dev/Week-of- Mon-20170529/001018.html •

    https:/ /lists.swift.org/pipermail/swift-build-dev/Week-of- Mon-20170605/001019.html • Building a command line tool using the Swift Package Manager • https:/ /www.swiftbysundell.com/posts/building-a-command- line-tool-using-the-swift-package-manager
  31. Q&A