background preloader

Swift

Facebook Twitter

Swift - Overview. Introducing Swift 5.1 Swift 5.1 now makes it easier to create and share binary frameworks with others.

Swift - Overview

It also includes features that make it easier to design better APIs and reduce the amount of common boilerplate code. Key Features Module stability defines a new text-based module interface file that describes the API of a binary framework. Property wrappers introduce a general purpose syntax for defining custom access patterns for property values. Modern Swift is the result of the latest research on programming languages, combined with decades of experience building Apple platforms. Declare new types with modern, straightforward syntax.

Add functionality to existing types using extensions, and cut down on boilerplate with custom string interpolations. extension Player: Codable, Equatable {} import Foundation let encoder = JSONEncoder() try encoder.encode(player) print(player) Perform powerful custom transformations using streamlined closures. Designed for Safety Fast and Powerful Open Source. The Swift Programming Language: A Swift Tour. Tradition suggests that the first program in a new language should print the words “Hello, world” on the screen.

The Swift Programming Language: A Swift Tour

In Swift, this can be done in a single line: If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need a main function. You also don’t need to write semicolons at the end of every statement. This tour gives you enough information to start writing code in Swift by showing you how to accomplish a variety of programming tasks. Simple Values Use let to make a constant and var to make a variable.

Var myVariable = 42 myVariable = 50 let myConstant = 42 A constant or variable must have the same type as the value you want to assign to it. Let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Double = 70. Overview - Vapor Docs. Database Kit is a framework for configuring and working with database connections.

Overview - Vapor Docs

It helps you do things like manage and pool connections, create keyed caches, and log queries. Many of Vapor's packages such as the Fluent drivers, Redis, and Vapor core are built on top of Database Kit. This guide will walk you through some of the common APIs you might encounter when using Database Kit. Config Your first interaction with Database Kit will most likely be with the DatabasesConfig struct. // Create a SQLite database.let sqliteDB = SQLiteDatabase(...) // Create a new, empty DatabasesConfig.var dbsConfig = DatabasesConfig() // Register the SQLite database using '.sqlite' as an identifier.dbsConfig.add(sqliteDB, as: .sqlite) // Register more DBs here if you want // Register the DatabaseConfig to services.services.register(dbsConfig) Using the add(...) methods, you can register Databases to the config.

Full stack development with Swift and Vapor - iOS Conf SG 2020. Vapor. Getting Started - Vapor Docs. JWT (vapor/jwt) is a package for parsing and serializing JSON Web Tokens supporting both HMAC and RSA signing.

Getting Started - Vapor Docs

JWTs are often used for implementing decentralized authentication and authorization. Since all of the authenticated user's information can be embedded within a JWT, there is no need to query a central authentication server with each request to your service. Unlike standard bearer tokens that must be looked up in a centralized database, JWTs contain cryptographic signatures that can be used to independently verify their authenticity. If implemented correctly, JWTs can be a powerful tool for making your application horizontally scalable. Learn more about JWT at jwt.io. Tip If your goal is not horizontal scalability, a standard bearer token will likely be a better solution.

A comparison between NodeJS and Vapor.

Swift on Raspberry Pi

Vapor. Full-stack Swift: Getting Started with VAPOR + iOS. Full stack development with Swift and Vapor - iOS Conf SG 2020. Docs. This is the documentation for Vapor, a Web Framework for Swift that works on iOS, macOS, and Ubuntu; and all of the packages that Vapor offers.

Docs

Vapor is the most used web framework for Swift. It provides a beautifully expressive and easy to use foundation for your next website or API. Getting Started If this is your first time using Vapor, head to the Getting Started section to install Swift and create your first app. Like Vapor? Our small team works hard to make Vapor awesome (and free). Other Sources. Using Swift 3 on RaspberryPi — First web projet with Vapor. In this guide, we assume you follow this guide to prepare your RPi for Swift development.

Using Swift 3 on RaspberryPi — First web projet with Vapor

Before installing Vapor Toolbox, you need to add some dependencies sudo apt-get install git libcurl3 then execute Vapor Toolbox script curl -sL toolbox.vapor.sh | bash Normally, you should have a install log like this : Don’t be affraid to see Install failed, trying sudo, that’s because we don’t install Vapor to system level but only on user level (like we doing with Swift before) What are the differences? Swift Tutorial: Create a Simple Web App with Vapor and Swift.