Day 3 and 4 Flashcards

(5 cards)

1
Q

What is array ? and how to make one ? example -

A

Arrays are their own data type. It’s a list of data -all of the same data type., could be a list of strings , int ,double .

start and end arrays using square brackets, with commas between every item

var beatles = [“John”, “Paul”, “George”, “Ringo”]

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

What is index ? what does it help do ?
var beatles = [“John”, “Paul”, “George”, “Ringo”]
what would you do to print John using index ?

A

The position of an item in an array is commonly called its index.

It helps reading values out from an array, we ask for values by the position they appear in the array.

print(beatles[0])
0 because counting starts from 0 in swift.

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

How to add new item in array ?
var beatles = [“John”, “Paul”, “George”, “Ringo”]
1. add name Adrian to it.

A

.append()
beatles.append(“Adrian”)

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

create an empty array of scores and add items one by one ?

A

use : Array<Int>
t’s an array that holds integers. allows swift to know for sure that it always should be integer and stops us from adding others.</Int>

var scores = Array<Int>()
scores.append(100)
scores.append(80)
scores.append(85)
print(scores[1])</Int>

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