Beginner Swift Flashcards

1
Q

Property of an array that counts the number of items in a given array.

A

Var.count

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

What is an array?

A

A sequential list of variables. Always starts at 0, increments by one in order.

Var todo[string] = [“call”,”suck”]

To add a value on end:

todo += [“swallow”]

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

A single operator that can affect the resulting value of a variable.

A

Unary operators

++ increment
– decrement
- negative
! Means variable or constant is negated

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

Example of a function with a return type String..

A
func heyName(name: String) -> String {
     var greeting = "Hello \(name)"
     return greeting
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Allows you to create a new type that groups several related values.

A

Enum.

enum Coin {
case Penny, Nickel, Dime, Quarter
}

Penny etc are called “Members”

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

What is a Switch statement?

A
A switch statement considers a value and compares it against several possible matching patterns. It then executes an appropriate block of code, based on the first successful match.
switch somevalue {
     case value 1:
          respond to value 1
     case value 2, value 3:
          respond to value 2 or 3
     default:
          otherwise do this 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Adds an element to an array.

Can also update a car in middle of array.

A

Var.append( )

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

Property of an array that counts the number of items in a given array.

A

Var.count

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

What is an array?

A

A sequential list of variables. Always starts at 0, increments by one in order.

Var todo[string] = [“call”,”suck”]

To add a value on end:

todo += [“swallow”]

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

A single operator that can affect the resulting value of a variable.

A

Unary operators

++ increment
– decrement
- negative
! Means variable or constant is negated

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

Example of a function with a return type String..

A
func heyName(name: String) -> String {
     var greeting = "Hello \(name)"
     return greeting
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Allows you to create a new type that groups several related values.

A

Enum.

enum Coin {
case Penny, Nickel, Dime, Quarter
}

Penny etc are called “Members”

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

What is a Switch statement?

A
A switch statement considers a value and compares it against several possible matching patterns. It then executes an appropriate block of code, based on the first successful match.
switch somevalue {
     case value 1:
          respond to value 1
     case value 2, value 3:
          respond to value 2 or 3
     default:
          otherwise do this 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Adds an element to an array.

Can also update a car in middle of array.

A

Var.append( )

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

What is Concatenation? Provide an example.

A

Adding objects together:

var greeting = “Hello” + language

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

What is a mutable string? Provide an example.

A

A string that can be modified:

var language = “Swift”

17
Q

What’s an immutable string? Provide an example:

A

A string that can’t be modified:

let language = “Swift”

18
Q

What is a Struct? Provide an example.

A

A Struct allows you to create a new data type with stored properties:

struct Car {
var doors : Int
var wheels: Int
}

19
Q

Create an instance of the struct Car

Hint–make a sedan.

A

var sedan = Car(doors:4, wheels:4)

20
Q

When do you use an optional?

A

You use optional a in situations where a value may not be present. An optional says:

1) there IS a value, and it equals x, or
2) there ISNT a value at all (nil)

21
Q

How do you make an optional?

A

Adding ? To a type makes it an optional.

22
Q

How can we unwrap an optional?

A

The bang ! Operator unwraps an optional, but using if let to unwrap even better.

–note, needs example