Skip to content

Swift the basics, Server-Side with Vapor and more ๐Ÿ˜๐Ÿš€

Notifications You must be signed in to change notification settings

YouClap/swift-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Swift a todo o "Vapor" ๐Ÿš‚

The basics, Server-Side using Vapor and more ๐Ÿ˜๐ŸŽ‰ ๐Ÿš€

Swift is an open source and high-performance language with a clean and modern syntax, that offers access to C code and is memory safe by default. ๐Ÿšจ

You can find more information at GitHub and Swift.org

Let's Start Cooking ๐Ÿฐ๐Ÿ‘จโ€๐Ÿณ๐Ÿ‘ฉโ€๐Ÿณ

And the first ingredient is Swift ๐Ÿฅš

You can run Swift on all the operating systems, some of them easily than in others.

There are some very good articles in the internet explaining how you can get Swift working on your system, i will provide some of them and also basic instructions.

macOS

This is the easiest one, you can get it in the nearest market, also known as AppStore ๐Ÿ›

Download Xcode from the AppStore

Now launch Xcode create a new playground and get ready to have some fun ๐ŸŽฎ๐ŸŽณ

Linux

Now is where you need the blender and all the wooden spoon ๐Ÿคฃ

Unfortunately, only Ubuntu 14.04, 16.04 or 18.04 (64-bit), is fully supported by the community.

Let's install the swift dependencies

sudo apt install curl git clang libsqlite3-dev libblocksruntime-dev libncurses5-dev libicu-dev libpython2.7

Now download the swift 5.0 DEVELOPMENT toolchain version specific to your system and the corresponding signature, from the swift.org downloads page.

Download and import PGP keys into your keyring

wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -

Assmuning your download goes to the downloads folder in your system, i will provide basic commands to setup the swift toolchain that you just downloaded.

cd ~/Downloads
gpg --verify swift-<VERSION>-<PLATFORM>.tar.gz.sig
tar xzf swift-<VERSION>-<PLATFORM>.tar.gz
sudo cp -r swift-<VERSION>-<PLATFORM>/usr/* /usr

You also have to install SourceKit-LSP. SourceKit-LSP is an implementation of language server protocol to enable features like code completion and jump to definition for Swift. Although this is a project under heavy development ๐Ÿšง with a lot of changes almost every day.

Basically you have to clone the sourcekit-lsp, build it linked to your swift instalation and copy it to a location on your path.

Those are basic instructions if you followed my instructions to setup swift for linux:

cd /tmp
git clone https://www.github.com/apple/sourcekit-lsp.git
cd sourcekit-lsp
swift package update
swift build -Xcxx -I/usr/lib/swift -Xcxx -I/usr/lib/swift/Block
sudo mv .build/x86_64-unknown-linux/debug/sourcekit-lsp /usr/bin

Now let's build the libSwiftPM.so

cd /tmp
git clone https://github.com/apple/swift-package-manager.git
cd swift-package-manager
swift package update
swift build -Xcxx -I/usr/lib/swift
sudo mv .build/x86_64-unknown-linux/debug/libSwiftPM.so /usr/lib/swift/linux

Now let's build the extension for VSCode. VSCode is an Electron app and the extension built with JavaScript, so we need node and npm installed.

If you are used to this, you may use nvm i assume ๐Ÿ˜…, just make sure you are using node v11 to build the extension if not (shame on you again ๐Ÿคฃ๐Ÿ™ƒi'm kidding).

If you are not used to this and you don't have node and npm installed, you can install it with

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt install -y nodejs

Now let's build the extension and install the extension

cd /tmp/sourcekit-lsp/Editors/vscode
npm run createDevPackage
code --install-extension out/sourcekit-lsp-vscode-dev.vsix

Windows

It is possible to run Swift on Windows, although not as easy as for Linux or macOS, of course ๐Ÿ˜.

https://swiftforwindows.github.io/

This information was gathered from a few articles (do not blame me ๐Ÿคฃ)

The Second Ingredient is Vapor ๐Ÿž

macOS

I'm assuming you know what brew is, if you don't shame on you ๐Ÿคฃ๐Ÿ™ƒ (i'm kidding). It's just the best package manager for macOS, if you don't have it ๐Ÿ‘‰ https://brew.sh/

Brew to the rescue, install vapor with two simple commands

brew tap vapor/tap
brew install vapor/tap/vapor

Linux

Unfortunately, Vapor toolbox is not compiled to work with Swift 5 yet. We will have to wait.

We will by pass this by downloading a pre-created project from a likk that i will provide later.

If you want to give a shot making Vapor working with Swift 5 on linux and sourcekit, check out those links to see if they can help you ๐Ÿ™‚

Let's mix the ingredients ๐Ÿฅง

As Quim Barreiros says, let's use pressure cooker to see if we cook faster ๐Ÿคฃ.

In this case and since vapor toolbox doesn't work well with linux and swift 5, you can download the bootstrap project from here

Or if you prefer, a better way to download

curl -L -O https://github.com/YouClap/swift-workshop/raw/master/bookstore.tar.gz

And uncompress it

tar xfz bookstore.tar.gz

About

With โค๏ธ from YouClap Development team

About

Swift the basics, Server-Side with Vapor and more ๐Ÿ˜๐Ÿš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published