Swift Web Dev Flashcards
What is swiftenv?
swiftenv allows you to easily install, and switch between multiple versions of Swift.
Change the global Swift version, per user.
Set a per-project Swift version.
Allows you to override the Swift version with an environmental variable.
How do you change global versions of swift? - eg from 4.0 to 3.0.2
cd /Desktop
swiftenv global 3.0.2
How do you run a local version of swift? (eg 3.0.1)
// on desktop mkdir local_version_swift
swiftenv local 3.0.1
This sets the swift version to 3.0.1 when we rung Swift from within this /local_version_swift directory
It does this by created a hidden file called .swift-versoin
You can make other local directories in /local_version_swift to use other versions
What is REPL?
Read-Eval-Print-Loop (REPL) is a way to interact with Apple’s Swift in the terminal.
Lesson 1: Episode 7.
Explain breifly what was learned here re using multiple sources files to carry out an executable
(hint: a file with a function we created and a struct from Github library - Playing Cards - Queen of hearts)
// Import package from GitHub
xxx enter code tomorrow xxx
run Package.swift. NB. The PlayCard(rank: suit:) is imported from GitHub so you don’t have to make a nano file
// eg From /Users/fergs/Desktop/HelloSwift, run ‘nano Sources/HelloFunction.swift’. The sayHello function is created in this file
func sayHello(name: String) { print("Hello, \(name) from Swift!) }
xxxx
// Then combine both functions in main.swift, run ‘nano Sources/main.swift’. The executable function is created in this file
import PlayingCard
let card = PlayingCard(rank: .queen, suit: .hearts) sayHello(name: "\(card)")
// ^^^ This combines both files and executes them. It uses sayHello, and passes it the PlayingCard function
// To run it go to /HelloSwift directory run the following to execute the code
.build/debug/HelloSwift
NB. The PlayCard(rank: suit:) is imported from GitHub so you don’t have to make a nano file. The sayHello func and the PlayingCard struct (ie same as func) are combined in the .main.swift