DEV Community

Cover image for Swift além do iOS e do macOS - Parte 1
Rafael Leandro
Rafael Leandro

Posted on

2 2

Swift além do iOS e do macOS - Parte 1

Eu trabalho com desenvolvimento iOS e não costumo fazer nada no backend, o que é um problema em projetos pessoais. Não quis investir tempo estudando JS e seus frameworks (não tenho nem espaço pro cache do npm) e comecei a procurar uma solução mais prática, foi aí que encontrei o Vapor.

Instalação

🍎 A instalação do Vapor é feita através do homebrew

$ brew install vapor
Enter fullscreen mode Exit fullscreen mode

Para ter certeza que a instalação foi feita corretamente:

$ vapor
Enter fullscreen mode Exit fullscreen mode

E essa deve ser a saída:

Usage: vapor <command>

Vapor Toolbox (Server-side Swift web framework)

Commands:
       build Builds an app in the console.
       clean Cleans temporary files.
      heroku Commands for working with Heroku
         new Generates a new app.
         run Runs an app from the console.
             Equivalent to `swift run --enable-test-discovery Run`.
  supervisor Commands for working with Supervisord
       xcode Opens an app in Xcode.

Use `vapor <command> [--help,-h]` for more information on a command.
Error: Missing command
Enter fullscreen mode Exit fullscreen mode

🐧 No Linux é necessário que o Swift 5.2 (ou superior) esteja instalado.
A instalação é feita compilando o toolchain.

git clone https://github.com/vapor/toolbox.git
cd toolbox
git checkout <versao>
make install
Enter fullscreen mode Exit fullscreen mode

Hello, Vapor.

Criando um novo projeto:

vapor new first-project -n
cd first-project
Enter fullscreen mode Exit fullscreen mode

A flag -n responde não automaticamente para todas as perguntas feitas depois de clonar o template.

Captura de Tela 2021-07-15 às 11.13.32

Rodando o primeiro projeto:
🍎 no macOS

vapor xcode
Enter fullscreen mode Exit fullscreen mode

🐧 no Linux

swift run
Enter fullscreen mode Exit fullscreen mode

Se tudo ocorrer bem, a saída no console deve ser essa:

[ INFO ] Server starting on http://127.0.0.1:8080
Enter fullscreen mode Exit fullscreen mode

E pra testar, basta abrir o endereço no navegador.

Captura de Tela 2021-07-15 às 11.23.05

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)

Billboard image

📊 A side-by-side product comparison between Sentry and Crashlytics

A free guide pointing out the differences between Sentry and Crashlytics, that’s it. See which is best for your mobile crash reporting needs.

See Comparison

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay