Making iOS Development Efficient with Swift

Making iOS Development Efficient with Swift

5eee847529e8f5ec2f634a85075fd5aa?s=128

Satoshi Hachiya

July 15, 2017
Tweet

Transcript

  1. Making iOS Development Efficient with Swift MobileOptimized 2017 July 15th,

    2017 Satoshi Hachiya / @jpmartha_jp
  2. None
  3. Satoshi Hachiya • Japanese iOS developer at ookami, Inc.

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

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

    Making an iOS application, Player!
  6. Satoshi Hachiya • Japanese iOS developer at ookami, Inc. •

    Making an iOS application, Player! • Organizer of try! Swift • Tokyo, NYC, India
  7. 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...
  8. Agenda

  9. Agenda • Using the REPL • What is the REPL?

  10. Agenda • Using the REPL • What is the REPL?

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

    • Using the Swift Package Manager • What is the Swift Package Manager? • Aproaching to the practical use
  12. Get Started! !

  13. Using the REPL

  14. 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
  15. Example Using the REPL

  16. 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>
  17. Typing 1> let country = "Belarus"

  18. Result 1> let country = "Belarus" country: String = "Belarus"

  19. Typing 1> let country = "Belarus" country: String = "Belarus"

    2> print("Hello, \(country)!")
  20. Result 1> let country = "Belarus" country: String = "Belarus"

    2> print("Hello, \(country)!") Hello, Belarus!
  21. 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!
  22. Example Importing Module

  23. Typing 1> import Darwin

  24. Typing 1> import Darwin 2> let cwd = getcwd(nil, Int(PATH_MAX))

  25. Result 1> import Darwin 2> let cwd = getcwd(nil, Int(PATH_MAX))

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

    cwd: UnsafeMutablePointer<Int8>? = 0x0000000100800000 3> let path = String(validatingUTF8: cwd!)
  27. 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"
  28. Typing $ swift --help

  29. 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
  30. Using the Swift Package Manager

  31. Swift Package Manager $ swift package $ swift build $

    swift test $ swift run
  32. $ swift package Typing $ swift package --help

  33. 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
  34. $ swift build Typing $ swift build --help

  35. 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
  36. $ swift test Typing $ swift test --help

  37. 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
  38. $ swift run Typing $ swift run --help Result OVERVIEW:

    Swift compiler !
  39. 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
  40. Example Creating Package

  41. Typing $ mkdir CommandLineTool $ cd CommandLineTool $ swift package

    init --type executable
  42. Result Swift 4 Creating executable package: CommandLineTool Creating Package.swift Creating

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

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

    [], targets: [ .target( name: "CommandLineTool", dependencies: []), ] )
  45. main.swift print("Hello, Belarus!")

  46. Example Building Package

  47. Typing $ swift build

  48. Result Compile Swift Module 'CommandLineTool' (1 sources) Linking ./.build/debug/CommandLineTool

  49. Example Executing Package

  50. Typing $ ./.build/debug/CommandLineTool

  51. Result Hello, Belarus!

  52. Example Importing Module • Importing Darwin • For linux, import

    Glibc • Getting the path of the current woriking directory
  53. 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)") }
  54. Typing $ ./.build/debug/CommandLineTool

  55. Result "/Users/CommandLineTool"

  56. Example Adding Dependencies https:/ /github.com/kylef/Commander - Compose beautiful command line

    interfaces in Swift
  57. 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"]), ] )
  58. Dependencies Swift 4 .package(url: "https://github.com/kylef/Commander.git", from: "0.1.0"), Swift 3.1 .Package(url:

    "https://github.com/kylef/Commander.git", majorVersion: 0),
  59. Example Building Package with Dependencies

  60. Typing $ swift build

  61. 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
  62. Example Releasing Package • -static-stdlib • Statically link the Swift

    standard library
  63. Typing $ swift build -c release -Xswiftc -static-stdlib

  64. 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
  65. Practical Use

  66. 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
  67. 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) ] )
  68. Conclusion • Using the REPL • Using the Swift Package

    Manager • Aproaching to the practical use
  69. 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
  70. My Issue Migration my command line tools to Swift 4

    • https:/ /github.com/tryswift/tryswiftdev • Downloading Swift snapshot file • README Generator • etc.
  71. 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
  72. Q&A