Search code examples
swift4xcode9vapor

Vapor doesn't work with xcode 9 and swift 4


When I try to compiled my newly created vapor project with Xcode 9 I get 189 compile errors. What's the trick to making this work? I installed vapor and the toolbox, and create via 'vapor new test --template=api' and then 'vapor xcode' to start it up.


Solution

  • Xcode 12 / Swift 5.3 Update

    vapor is now part of homebrew/core. Source: github homebrew-core/Formula/vapor.rb.

    ##### If applicable, remove the obsolete 'vapor/tap' #####
    ## List current taps:
    brew tap
    # homebrew/core
    # vapor/tap
    ## Remove tap:
    brew untap vapor/tap
    
    #### Install current version of vapor #####
    brew install vapor
    brew upgrade vapor
    

    Xcode 9 / Swift 4

    Check that everything is up to date. The following builds and runs for me at this time:

    Use latest vapor toolbox.

    Currently:

    vapor new test --template=api
    cd test
    swift package tools-version
    # 4.0.0
    # use `swift package tools-version --set-current` if needed
    rm Package.resolved
    vapor update
    vapor --version
    # Vapor Toolbox: 3.1.2
    # Vapor Framework: 2.3.0
    

    Note, Vapor Framework:__ only shows when the terminal working directory pwd is pointing to a vapor project directory.

    If needed ...

    brew tap --full  vapor/homebrew-tap
    brew update 
    brew upgrade
    

    In some cases the vapor toolbox may need to be deleted and reinstalled. (see "vapor toolbox broken after upgrading swift")

    Use latest Xcode release.

    Currently: Xcode: 9.1, Swift: 4.0.2

    swift --version
    # Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
    

    Use vapor update or swift package update

    vapor new test --template=api
    cd test
    rm Package.resolved
    vapor update
    

    alternately,

    vapor new test --template=api
    cd test
    rm Package.resolved
    swift package update
    swift package generate-xcodeproj
    

    The above updates, compiles and runs OK for me in Xcode 9.1.

    Note: However, there are about 44 new deprecation warnings of the same type. I first became aware of the characters deprecation with Xcode9.1/Swift4.0.2.

    'characters' is deprecated: Please use String or Substring directly"

    So, new deprecation warnings, but 0 errors ... and, more importantly, the project runs as Vapor 2 + Swift 4.

    Also, check Packages.resolved versions versus what is available in each respective source repository. On github, the Vapor Examples Lab: TemplateApiTest repository contains the Packages.resolved which was generated and works with the tool chain scenario above.

    Finally, double check that the target is Run on macOS and not an ARM-based iOS for this build.

    Xcode schema Run > My Mac