Swift Flashcards

1
Q

Déclaration d’une variable et constante

A
  • var myVariable = 2
  • let myConstant = 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Déclaration implicte et explicite

A

var implicitVar = 2

var explicitVar: Int = 2

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

Déclaration array

A

var myArray = []

var myArray = [“element1”, “element2”]

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

Ajout d’un array programatiquement

A

myArray.append(“element3”)

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

For loop

A

var list = […]

for varName in list {…}

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

Déclaration d’une fonction et appelle d’une fonction

A

func functionName(arg1: arg1Type) -> returnType {…}

functionName(arg1: “test”)

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

Fonction avec plusieurs retours

A

func calculateStats(scores: [Int]) -> (min: Int, max: Int, sum: Int) {

return (min, max, sum)

}

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

Fonction avec fonction comme retour

A

func makeIncrement() -> ((Int) -> Int) {

func addOne(number: Int) -> {…}

}

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

Instanciation d’une classe

A

var shape = Shape()

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

Accéder aux propriétés et méthodes

A

Avec les points comme dans java

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

Constructeur d’une classe

A

Avec init()

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

Getter and Setter à l’intérieur d’une variable dans une classe

A

var sideLenght : double = 0.0

var perimeter: Double {

get {

return 3.0 * sideLength

}

set {

sideLength = newValue / 3.0

}
}

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