Server Side Swift with Vapor - Part 2: Hello World | Ray Wenderlich

@rubiriffic @ckbrown - Iā€™ve just tried to see whatā€™s working at the moment. Looks like that kind of parameter routing isnā€™t in yet, youā€™ll need to stick to using String.parameter and pulling out all of them and only using the ones you want for now. Iā€™ve asked in Slack to see what the status/plan is for this kind of thing. (Though I would still argue if you are throwing away a dynamic parameter you have a design issue)

1 Like

actually no I didnā€™t run that, I missed the part where you said this would get the beta branch of Vapor and I thought you were creating a local branch called ā€˜betaā€™ so I skipped it because I didnā€™t really care about git at the moment. Guess I should have paid closer attention! lol

Ha! No the --branch=beta specifies which branch of the template to use

Iā€™m getting no such module name Vapor in my application

@averma12 have you done a build first? Xcode can get confused with some modules the first time

My build is failing but Iā€™m not getting why.
/Users/abhinavverma/Desktop/vapor/Hello_vapor/.build/checkouts/crypto.git-7980259129511365902/Sources/Crypto/Cipher/Cipher+Method.swift:1:8: error: could not build Objective-C module ā€˜CTLSā€™
import CTLS
I got an error of brew link cels. that command had failed when I was setting up my vapour toolbox.

@averma12 are you definitely on Vapor 3? What does your Package.swift file look like? It should have .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"), in it. If it says .upToNextMajor("2.1.0") then you are on Vapor 2. Iā€™m pretty sure CTLS isnā€™t required for Vapor 3.

Your code :
let name = try req.parameter(String.self)

your code donā€™t work for me
Because function parameter is changed

Correct code
let name = try req.parameters.next(String.self)

@lashkari are you definitely on Vapor 3? Did you pass in the --branch=beta flag when you created the project? let name = try req.parameters.next(String.self) is for Vapor 2

vapor version
Vapor Toolbox: 3.1.4

@lashkari what does your Package.swift look like?

The toolbox is different to the framework

1 Like

how to change and update this ?

The easiest way will be to start from scratch. In terminal run:

cd ~/vapor
rm -rf HelloVapor
vapor new HelloVapor --branch=beta
1 Like

iā€™m using Swift 4.1 snapshot , and in terminal using this code
vapor new HelloVapor --branch=beta

but in Xcode i have one error
No such module ā€˜Appā€™
can you help me?

@lashkari make sure you do a build first - sometimes Xcode can get confused with SPM when it hasnā€™t built anything yet

The problem was solved
thanks a lot :pray:

1 Like

// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: ā€œHello_vaporā€,
products: [
.library(name: ā€œAppā€, targets: [ā€œAppā€]),
.executable(name: ā€œRunā€, targets: [ā€œRunā€])
],
dependencies: [
.package(url: ā€œGitHub - vapor/vapor: šŸ’§ A server-side Swift HTTP web framework.ā€, .upToNextMajor(from: ā€œ2.1.0ā€)),
.package(url: ā€œGitHub - vapor-community/fluent-provider: A provider for including Fluent in Vapor applicationsā€, .upToNextMajor(from: ā€œ1.2.0ā€)),
],
targets: [
.target(
name: ā€œAppā€,
dependencies: [ā€œVaporā€, ā€œFluentProviderā€],
exclude: [ā€œConfigā€, ā€œPublicā€, ā€œResourcesā€]
),
.target(name: ā€œRunā€, dependencies: [ā€œAppā€]),
.testTarget(name: ā€œAppTestsā€, dependencies: [ā€œAppā€, ā€œTestingā€])
]
)

@averma12 yeah thatā€™s Vapor 2. See this post, which should help:

Terminal:
eval ā€œ$(curl -sL check.vapor.sh)ā€:
:white_check_mark: Xcode 9 is compatible with Vapor 2.
:white_check_mark: Xcode 9 is compatible with Vapor 3.
:white_check_mark: Swift 4.0 is compatible with Vapor 2.
:x: Swift 4.1 or later is required for Vapor 3.

Tried this solution:

Looks like I need to update to 4.1 in vapor?

Clicked build before making any changes, build successful, but as soon as I click on main.swift I get an error next to ā€œimport Appā€:
ā€œModule compiled with Swift 4.1 cannot be imported in Swift 4.0.3: /Users/xxx/Library/Developer/Xcode/DerivedData/HelloVapor-gsmlftoylwgkmsgzoxnghlvcnzug/Build/Products/Debug/App.framework/Modules/App.swiftmodule/x86_64.swiftmoduleā€

@doyle yes youā€™ll need Swift 4.1 for Vapor 3. Howeverā€¦ if you have installed Swift 4.1 as a toolchain in Xcode, your command line version will be Swift 4.0.

If it builds ok but you get errors popping up - I would ignore it, it is probably Xcode caching errors :unamused:

They should go away, but if you clean the project (and delete Derived Data) you should be fine

1 Like