Image for post
Image for post
Vapor 4 — Server Side Swift

In this article we are going to see how we can migrate a web application, developed in Vapor 3 to the newest version, Vapor 4. This article can also be found on my personal website.

Short recap

We saw together in this article how we can develop a basic REST API in Vapor 3.

The server side app structure in Vapor 3:

├── Public
├── Sources
│ ├── App
│ │ ├── Controllers
│ │ ├── Models
│ │ ├── boot.swift
│ │ ├── configure.swift
│ │ └── routes.swift
│ └── Run
│ └── main.swift
├── Tests
│ └── AppTests
└── Package.swift

  • This is the manifest of the project and defines all dependencies and targets of our app.
    The project is pointing to Vapor 3.3.0:
    package(url: “https://github.com/vapor/vapor.git", …

Image for post
Image for post

Motivation

I was looking for an alternative to OHTTPStubs to use in my unit tests for network responses and WireMock catch my eyes. It is written in Java, can be run as a standalone process, is simple to use and I don’t make my project/app dependent on a 3rd party by importing it in my unit test files.

Stubbing vs Mocking

A stub is something that has a predefined behaviour. You know that if you call method X, you will get result Y. For each of our API requests, we will have JSONs that will be sent as responses.

Example

POST /users {“firstName”: “John”, “lastName”: “Smith”}
And the JSON file ‘register-stub.json’ will always return as part of the response ‘200 OK’. …


Image for post
Image for post

Motivation

Everybody is talking about #wwdc19 and how SwiftUI is drawing the future and I am here writing a snippet about calendars.

Well, if you want to be a time traveller and see if SwiftUI will be a changer on how the UI will be created for iOS apps, let’s first open up a Calendar.

This article helps you understand what are the differences between calendar.current and calendar.autoupdatingCurrent and when to apply them.

Setting up

There are two ways of retrieving user’s calendar: .current and .autoupdatingCurrent.
If you open Apple’s documentation, is saying that .current is not tracking changes that user makes to their settings.
On the other hand, .autoupdatingCurrent tracks changes to the user’s preferred calendar. …


Image for post
Image for post

Motivation

Ever wanted to store some information in a place where is secure? Maybe you heard that UserDefaults, CoreData are not that great in storing sensitive data, such as passwords, being more vulnerable to attackers.

What about a special place in your device called Keychain?! By special place we mean an encrypted database where you can put users data.

Each application on an iOS device have access to a single keychain. If you build an app you have access to your own items or those that are shared with a group which the app belongs to.

You are not limited storing just passwords. You can put in the keychain secrets, keys, credit card information or notes. …


Image for post
Image for post

Motivation

This article gives you a snippet of what is ‘nil’, ‘Void’ and ‘Never’ in Swift terminology.
We want to cover some basic usage of these three keywords so you will have a clear understanding of their differences.

nil

The absence of a value.

When we are saying nil, we are bringing to the table Swift’s optionals. Optionals say either “there is a value, and it equals x” or “there isn’t a value at all” [1].

Under the hood an Optional is an enum:

Example:

Void

A return type that doesn’t return a value.

Void is an empty tuple (). It is implemented with a…


Image for post
Image for post

Swift is awesome. Yes, it’s mature (now with 5.0 we have ABI stability, hooray!). You have the power of OOP, POP, functional and imperative programming in your hands.

You can do almost anything in Swift nowadays. If you ever thought of being a full stack developer with knowing both backend and frontend, then this article is for you.
The most known web frameworks written in Swift are Kitura and Vapor.
Vapor is now at version 3 (released in May, 2018), is open source and you can easily create your REST API, web application or your awesome website.

In this tutorial you will…

About

Radu Dan

iOS Developer / Doing magic things in Swift

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store