Serverside Swift
Content
- Basics
- Terminologies
- Commands
- Docker Images
- Image Types
- Create Images
- Docker Compose
docker-compose.yml
- Run Application
Create Swift Package
swift package init
swift build
swift package generate-xcodeproj
Package.swift
name: name of package
targets: binary files
dependencies: [
.Package(url: "url", majorVersion: version, minor: version)
]
Swift Basics
Strongly-Typed
var myVar = "string"
or var myVar: String
var myInt = Int(myVar)
or var myInt = (myVar as NSString).integerValue
Constants & Variables
let const = value
vs var const = value
Class
class MyClass {
var myName = "name"
func myFunc(_ name:String) -> String { // unnamed parameter
return "Hello \(myName)"
}
static func myStaticFunc(name: String = "default") -> String { // named parameter
return "Hello \(myName)"
}
}
let this = MyClass()
print(this.myFunc("name"))
print(MyClass.myStaticFunc(name:"name"))
Building Swift Applicstions
Targets
- Library
- Executable (terminal-like icon)
Settings
Target > Edit Scheme > Run > Options > Use custom working directory: [project-directory]