Swift Web Dev Flashcards

1
Q

What is swiftenv?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you change global versions of swift? - eg from 4.0 to 3.0.2

A

cd /Desktop

swiftenv global 3.0.2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you run a local version of swift? (eg 3.0.1)

A
// 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is REPL?

A

Read-Eval-Print-Loop (REPL) is a way to interact with Apple’s Swift in the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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)

A

// 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly