self study Flashcards

1
Q

What does Built-In mean?

A

Refers to functionalities, types, or features that are an integral part of the Swift language itself.

These are provided directly by the Swift standard library or are part of the Swift compiler, and they are readily available without the need for additional imports or external dependencies.

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

Functions and methods with no return type have an implicit return type of ______

A

Void

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

A struct is a ____ type

A

Value

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

A class is a ____ type

A

Reference

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

The language used by Apple before Swift:

A

Objective-C

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

Are variables always initialized before use?

A

Yes

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

Fundamental Data Types:

A

Integers, Double, Bool, String

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

Collection Types:

A

Array, Set, Dictionary

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

A tuple is an ____ type

A

Advanced

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

The language helps you to be clear about the types of values your code can work with.

For example, if your code requires a String, type safety prevents you from passing an Int by mistake

A

Type-Safe

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

Swift performs type-safe checks when ____ the code

A

Compiling

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

Must be declared before they’re used

A

Constants and Variables

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

Enables a compiler to deduce the type of a particular expression automatically when it compiles your code, simply by examining the values you provide

A

Type Inference

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

Write a ___________ by placing a colon after the constant of variable name, followed by a space, followed by the name of the type to use

A

Type Annotation

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

In the following code, the “String” word can be defined as:

var myWord: String

A

Type Annotation

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

It’s a value that appears directly in your source code. The number 42 is a ______

E.g let meaningOfLife = 42

A

Literal Value

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

If you need to give a constant or variable the same name as the reserved Swift keyword, surround the keyword with ____

A

backticks (`)

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

Include the name of a constant or variable as a placeholder in a longer string

A

String interpolation

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

How do you represent, single, multiple lines comments?

A

// Single line


/* Multiple lines */


/* This is the start of the first multiline comment.
 /* This is the second, nested multiline comment. */
This is the end of the first multiline comment. */

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

Whole numbers with no fractional component, Signed positive, zero, negative.

A

Integers

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

Represents a 64-bit floating-point number and it is preferred and inferred when you don’t specify a type

A

Double

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

Values are referred to as logical because they can only be true or false

A

Booleans (Bool)

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

The values within a ____ can be of any type and don’t have to be of the same type as each other

A

tuple

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

You can ____ a tuples contents into separate constants or variables

A

decompose

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

This is an example of a:

let http404Error = (404, “Not Found”)

A

Tuple

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

Define an alternative name for an existing type and use the keyword ____

A

Type Aliases

typealias

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

You use ____ in the situation where a value may be absent, it represents two possibilities:
Either there is a value of a specified type, and you can unwrap the ____ to access that value, or there isn’t a value at all

A

Optionals

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

If you define an optional variable without providing a default value, the variable is automatically set to ____

A

nil

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

Trailing question mark

A

?

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

You must ____ the value of an Optional instance before you can use it in many contexts

A

unwrap

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

Mention the ways to safely unwrap optional values

A

*Optional Binding
*Optional Chaining
*Nil-Coalescing Operator
*Force unwrapping / Unconditional Unwrapping

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

This is useful when an optional’s value is confirmed to exist immediately after the optional is first defined and can definitely be assumed to exist at every point thereafter.

A

Implicitly Unwrapped Optional

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

To conditionally ____ the wrapped value of an Optional instance to a new variable, use one of the optional ____ control sources

A

bind / binding

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

This safely unwrap optional value, includes:

if let, guard let, and switch

A

Optional binding

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

It’s a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil

A

Optional Chaining

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

Multiple queries can be chained together, and the entire chain ____ gracefully if any link in the chain is nil

A

falls

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

Postfix optional chaining operator

A

(postfix ?)

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

Use the ____ to supply a default value in case the Optional instance is ____

A

nil-coalescing operator / nil

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

nil-coalescing operator

A

??

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

When you are certain that an instance Optional contains a value, you can unconditionally unwrap the value by using the ____ operator

A

force unwrap

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

Forced unwrap operator

A

(postfix !)

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

Unconditionally unwrapping a nil instance with ! Triggers a ____

A

runtime error

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

This is an example of a ____

let assumedString: String! = “Hello”

A

Implicitly Unwrapped Optional

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

Assertions and Preconditions are checks that happen ____, you use them to make sure an essential condition is satisfied before executing any further code.

A

a runtime

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

If the boolean condition in the assertion or precondition is ____, code execution continues as usual, if it’s ____, the current state of the program is invalid, code execution ends and your app is terminated.

A

true
false

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

____ help you find mistakes and incorrect assumption during ____, and ____ help detect issues in ____

A

Assertions
development
preconditions
production

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

Which is the difference between assertions and preconditions ?

It’s when they are ____

Assertions are checked only in ____ builds.

Preconditions are checked in both ____ and ____ builds.

A

Checked
debug
debug
production

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

in production builds, the condition inside an assertion is evaluated.

A

No

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

You write an assertion by calling the ____ function


A

assert(::file:line:)

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

If the code already checks for the condition, you use ____ function to indicate that an assertion has failed

A

assertionFailure(::file:line:)

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

You write precondition by calling ____ function

A

precondition(::file:line:)

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

You can also call the ____ function to indicate that a failure has occurred

A

preconditionFailure(::file:line:)

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

Defines a blueprint of methods, properties, and any other requirements that suit a particular task or piece of functionality

A

Protocol

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

A protocol defines a ____ of ____ and ____

A

blueprint
methods
properties

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

A protocol can be adopted by a ___, ___ and ___

A

class
struct
enum

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

Any time that satisfies the requirements of a protocol is said to ____ to that protocol

A

conform

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

You can ____ a protocol

A

extend

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

Can multiple protocols be listed?

A

Yes, separated by commas

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

If a class has a superclass, list a superclass ____ the protocols

A

before

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

Why do protocols begin with a capital letter?

A

Because protocols are types

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

Protocol doesn’t specify whether the property should be stored or computed, it only specifies whether each property must be ____, or ____and ____.

A

gettable
gettable
settable

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

what is it
var mustBeSettable: Int { get set }

A

A property declared in a protocol

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

Default values, however, can’t be specified for method parameters within a protocol’s definition

True or False?

A

True

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

Protocols can require specific initializers to be implemented by conforming types.

protocol SomeProtocol {
init(someParameter: Int)
}

True or False?

A

True,
You write these initializers as part of the protocol’s definition in exactly the same way as for normal initializers, but without curly braces or an initializer body

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

Mutating keyword only applies to ____

A

structs

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

To force a protocol to be limited to class types only, you can add the ____ protocol to its inheritance list

A

AnyObject

protocol SecretClassFeature:AnyObject {

func secretClassFeature () 

}

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

What does the delegation design pattern do?

A

Enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type

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

delegates are declared as ____ references

A

weak

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

A protocol can be used as the type to be stored in a collection such as an array or a dictionary?

True or False

A

True

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

A protocol can ____ one or more protocols and can add further requirements on top of the requirements it inherits.

A

inherit

protocol InheritingProtocol: SomeProtocol, AnotherProtocol {

}

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

what is protocol composition?

A

You can combine multiple protocols into a single requirement

You can also create a typealias using protocol composition



typealias RobotQ = Bipedal & PetrolPowered

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

What are Optional Protocol Requirements?

Which is the optional modifier?

A

You can define optional requirements of protocols. These requirements don’t have to be implemented by types that conform to the protocol.

Those are prefixed with the optional modifier, Both the protocol and the optional requirement must be marked with the @objc attribute,

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

What are extensions?

A

Allow you to add brand-new functionality to existing classes, structures, and protocols. You can use extensions to add computed properties, methods, or initializers, or make something conform to a protocol.

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

Extensions can add methods and computed properties, but not ____ properties

A

stored

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

Assignment operator

A

=

76
Q

Equal operator

A

==
Returns a boolean

77
Q

+ - * /

A

Arithmetic Operators

78
Q

%

A

Reminder or modulo operator

79
Q

+=

A

Compound operator

80
Q

1…5

A

Closed Range operator

81
Q

a..<b

A

Half Open Range Operator

82
Q

2… or …2

A

One-Sided Ranges

83
Q

NOT !a
AND ( && )
OR (a | | b )

A

Logical Operators

84
Q

Name the logical operators

A

NOT !a
AND ( && )
OR (a | | b )

85
Q

____ operator appears immediately before their target

A

Unary prefix
!c

86
Q

____ operator appears immediately after their target

A

Unary postfix
c!

87
Q

____ operators operate on two targets, Example: 2 + 3, and are ____ because they appear in between two targets

A

Binary Operators
infix

88
Q

____ operators operate on three targets, ternary conditional operator (a ? b : c)

A

Ternary

89
Q

String is a ____ type

A

Value
it means that the value is copied

90
Q

What is a String?

A

A series of characters

91
Q

From which class comes String?

A

Foundation’s NSString class

92
Q

A ____ is a sequence of characters surrounded by double quotation marks (“)

A

A string literal

93
Q

You can append a character value to a String variable with the String type’s ____ method

A

append()

94
Q

Can you append a String or Character to an existing Character variable?

A

No, because a Character value must contain a single character only

95
Q

____ is an international standard for encoding, representing, and processing text in different writing systems

A

Unicode

96
Q

To retrieve a count of the character values in a string, use the ____ property of the string

A

count()

var word = “cafe”
 word.count()

97
Q

____ property to access the position of the first character of a String

A

startIndex

98
Q

____ property is the position after the last character in a String

A

endIndex

99
Q

You can access the indices before and after a given index using the ____ and ____ methods of String

A

index(before:)
index(after:)

100
Q

To access an index farther away from the given index, you can use ____ method

A

index(_:offsetBy:)

101
Q

To insert a single character into a string at a specified index, use the ____ method

A

insert(_:at:)

102
Q

To insert the contents of another string at a specified index, use the ____ method

A

insert(contentsOf:at:)

103
Q

To remove a single character, from a string at a specified index, use ____ method

A

remove(at:)

104
Q

To remove a substring at a specified range, use the ____ method

A

removeSubrange(_:)

105
Q

When you get a substring from a string, the result is an instance of ____ not another string

A

substring

106
Q

Two string values (or two Character values) are considered equal if their extended grapheme clusters are canonically equivalent

True or False?

A

True

107
Q

To check whether a string has a particular string prefix or suffix, call the string’s ____ and ____ methods, both take a String and return a ____ value

A

hasPrefix(:)
hasSuffix(
:)
Boolean

108
Q

Array, set and dictionaries are ____ when assigned to a variable, this means that can change or mutate the collection after it’s created by adding, removing or changing items in the collection, but are ____ when assigned to a constant, and it’s size contents ____ be changed

A

mutable
immutable
can’t

109
Q

Which Collection Type is it?
Ordered collection of values

A

Array

110
Q

Which Collection Type is it?
Always zero-indexed

A

Array

111
Q

If you try to access or modify a value for an index that’s outside of an array’s existing bounds, you will trigger a ____.

A

runtime error

112
Q

What does the following code do?
var emptyArray: [Int] = []

A

It creates an empty array

113
Q

Write the code to create an empty array:

A

var emptyArray: [Int] = []

114
Q

Explain the following code:
var shoppingList: [String] = [“Eggs”, “Milk”]

This is an array ____

A

literal

115
Q

Why shoppingList doesn’t have a type?

var shoppingList = [“Eggs”, “Milk”]

A

Type inferences don’t need to write the type of the array

116
Q

Property to verify if a an arrary is empty?

A

.isEmpty

if shoppingList.isEmpty {
 print(“The shopping list is empty.”
} else {
 print(“The shopping list isn’t empty.”
}

117
Q

Method to add a new item at the end of the array

A

append(_:)method

You can add a new item to the end of an array by calling the array’sappend(_:)method
shoppingList.append(“Flour”)

118
Q

Retrieve a value from the array by usingsubscript syntax, passing the ____ of the value

A

index

var firstItem = shoppingList[0]

119
Q

To insert an item into the array at a specified index, call the array’s____ method:

A

insert(_:at:)

shoppingList.insert(“Maple Syrup”, at: 0)


120
Q

You remove an item from the array with the____method


A

remove(at:)

let mapleSyrup = shoppingList.remove(at: 0)

121
Q

If you want to remove the final item from an array, use the____method

A

removeLast()

let apples = shoppingList.removeLast()

122
Q

If you need the integer index of each item as well as its value, use the____ method to iterate over the array instead. For each item in the array, the____method returns a tuple composed of an integer and the item.

A

enumerated()

123
Q

Explain the following code:

for (index, value) in shoppingList.enumerated() {
 print(“Item (index + 1): (value)”)
 }
// Item 1: Six eggs
// Item 2: Milk
// Item 3: Flour
// Item 4: Baking Powder
// Item 5: Bananas


A
124
Q

Unordered collection of unique values

A

Set

125
Q

var letters = Set<Character>()</Character>

A

Creating an empty set

126
Q

Coding:
Create an empty set

A

var letters = Set<Character>()</Character>

127
Q

Design Principles (6)

A

Aesthetic Integrity
Consistency
Direct Manipulation
Feedback
Metaphors
User Control

128
Q

Navigation Hierarchy (3)

A

Hierarchical
Flat
Content Driven or Experience Driven

129
Q

Navigation Design Guidelines (5)

A

Design an information structure that makes it fast and easy to get to content

Use standard navigation components

Use a navigation bar to traverse a hierarchy of data

Use a tab bar to present peer categories of content functionality

Use the proper transition style

130
Q

You can remove an item from a set by calling the set’s____method

A

remove(_:)

if let removedGenre = favoriteGenres.remove(“Rock”) {
 print(“(removedGenre)? I’m over it.”)
} else {
 print(“I never much cared for that.”)
}

131
Q

To check whether a set contains a particular item, use the____ method


A

contains(_:)

if favoriteGenres.contains(“Funk”) {
 print(“I get up on the good foot.”)
} else {
 print(“It’s too funky in here.”)
}
// Prints “It’s too funky in here.”

132
Q

You can iterate over the values in a set with a____

A

for-inloop

for genre in favoriteGenres {
 print(“(genre)”)
}
// Classical
// Jazz
// Hip hop


133
Q

Swift’sSettype doesn’t have a defined ordering. To iterate over the values of a set in a specific order, use the____ method

A

sorted()

for genre in favoriteGenres.sorted() {
 print(“(genre)”)
}
// Classical
// Hip hop
// Jazz

134
Q

A ____ stores associations between ____ of the same type and ____ of the same type in a collection with no defined ordering

A

dictionary
keys
values

135
Q

Each value is associated with a unique ____, which acts as an ____ for that value within the dictionary

A

key
identifier

136
Q

Unordered collections of key-value associations

A

Dictionary

137
Q

Code:
Create an empty dictionary

A

var namesOfIntegers: [Int: String] = [:]. //its keys are Int value and its values are of type String

138
Q

You find out the number of items in aDictionaryby checking its read-only____ property

A

count

var airports = [“YYZ”: “Toronto Pearson”, “DUB”: “Dublin”]
print(“The airports dictionary contains (airports.count) items.”)

139
Q

Use the Boolean____ property as a shortcut for checking whether thecountproperty is equal to0

A

isEmpty

140
Q

You can add a new item to a dictionary with subscript syntax. Use a new ____ of the appropriate type as the subscript index, and assign a new value of the appropriate type

A

key

var airports = [“YYZ”: “Toronto Pearson”, “DUB”: “Dublin”]
airports[“LHR”] = “London”

141
Q

You can also use subscript syntax to ____ the value associated with a particular key

A

change

var airports = [“YYZ”: “Toronto Pearson”, “DUB”: “Dublin”, “LHR”: “London”]
airports[“LHR”] = “London Heathrow”

142
Q

Remove a key-value pair from a dictionary by assigning a value of ____ for that key

A

nil
airports[“APL”] = nil

143
Q

Code:
Iterating over a dictionary

A

for (airportCode, airportName) in airports {
 print(“(airportCode): (airportName)”)
}

144
Q

____ are self-contained chunks of code that perform a specific task

A

Functions

145
Q

The ____ name is used in the implementation of the function

A

parameter

146
Q

Type of value that the function takes as input

A

parameter

147
Q

It’s used when calling the function

A

Argument

148
Q

To use a function, you “call” that function with its name and pass it input values (known as____) that match the types of the function’s ____

A

arguments
parameters

149
Q

What does the following mean?
Functions with an implicit return

A

it means that it’s NOT necessary to write the return keyword

func greeting(for person: String) -> String {

“Hello, “ + person + “!”

}

150
Q

Each function parameter has both an____ labeland a____ name. The ____ label is used when calling the function; each argument is written in the function call with its argument label before it. The ____ name is used in the implementation of the function. By default, parameters use their ____ name as their argument label

A

argument
parameter
argument
parameter
parameter

151
Q

You can define a____ for any parameter in a function by assigning a value to the parameter after that parameter’s type. If a default value is defined, you can ____ that parameter when calling the function

A

default value
omit

152
Q

Variadic Parameter

A

(…) the three dots are called an ellipsis.
A function can have only one variadic parameter

func arithmeticMean(_ numbers: Double…) -> Double {
 var total: Double = 0


for number in numbers {

total += number
 }

return total / Double(numbers.count)

}


arithmeticMean(1, 2, 3, 4, 5)

// returns 3.0, which is the arithmetic mean of these five numbers

153
Q

In-Out Parameters -> Variadic parameters ____ be marked as inout, &&

A

can’t

154
Q

____ A function that doesn’t have a return, This is simply an ____, which is written as____

A

Void
empty tuple
()

155
Q

Function’s signature:

A

Combination of its name plus its argument names and types, plus its return type

156
Q

Function type =

A

parameter types + return type

157
Q

Function Parameters are ____ by default.

A

constants

158
Q

Trying to change the value of a function parameter from within the body of that function results in a compile-time error.

This means that you can’t change the value of a parameter by mistake.

If you want a function to modify a parameter’s value, and you want those changes to persist after the function call has ended, define that parameter as an____ parameterinstead. ____ parameters can’t have default values, and variadic parameters can’t be marked asinout

A

in-out
In-out

func swapTwoInts(_ a: inout Int, _ b: inout Int) {

let temporaryA = a

a = b

b = temporaryA

}

var someInt = 3
var anotherInt = 107
swapTwoInts(&someInt, &anotherInt)

print(“someInt is now (someInt), and anotherInt is now (anotherInt)”)


159
Q

Nested Functions:

A

Nested functions are hidden from the outside world by default, but can still be called and used by their enclosing function.

An enclosing function can also return one of its nested functions to allow the nested function to be used in another scope

160
Q

____are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance ____, which encapsulate specific tasks and functionality for working with an instance of a given type

A

Methods
methods

161
Q

inside a class, structure or enum, are called ____

A

methods

162
Q

____are functions that belong to instances of a particular class, structure, or enumeration

A

Instance methods

163
Q

Structures and enumerations are ____ types. By default, the properties of a ____ type can’t be modified from within its instance methods

A

value

164
Q

if you need to modify the properties of your structure or enumeration within a particular method, you can opt in to____behavior for that method

A

mutating

Classes don’t need this keyword in the methods, because are reference type.

165
Q

Control Flow

A

For-In Loop
While Loop
repeat-while

Conditional statements:
If/else
Switch

166
Q

To iterate over the items in array, a dictionary to access its key-value pairs, numeric ranges

A

For-In Loop

167
Q

You can use this syntax to iterateanycollection, including your own classes and collection types, as long as those types conform to the____protocol.

A

Sequence

168
Q

Performs a set of statements until a condition becomes false

A

While Loop

169
Q

These kind of loops are best used when the number of iterations isn’t known before the first iteration begins

A

While Loop

170
Q

Evaluates its condition at the end of each pass through the loop

A

repeat-while

repeat {

<#statements#>

} while <#condition#>

171
Q

Conditional statements:

A

If/else
Switch

172
Q

Considers a value and compares it against several possible matching patterns

Clue: it’s a conditional statement

A

switch

173
Q

Everyswitchstatement must be____

A

exhaustive

174
Q

____: Aswitchcase can name the value or values it matches to temporary constants or variables, for use in the body of the case. This behavior is known as____ , because the values are bound to temporary constants or variables within the case’s body

A

Value bindings

175
Q

Aswitchcase can use a____clause to check for additional conditions

A

where

176
Q

____: Multiple switch cases that share the same body can be combined by writing several patterns aftercase. ____ can also include value bindings

A

Compound cases

let someCharacter: Character = “e”


switch someCharacter {

case “a”, “e”, “i”, “o”, “u”:

print(“(someCharacter) is a vowel”)

case “b”, “c”, “d”, “f”, “g”, “h”, “j”, “k”, “l”, “m”,
”n”, “p”, “q”, “r”, “s”, “t”, “v”, “w”, “x”, “y”, “z”:

print(“(someCharacter) is a consonant”)

default:

print(“(someCharacter) isn’t a vowel or a consonant”)
}
//

Prints “e is a vowel”

177
Q

____: Change the order in which your code is executed, by transferring control from one piece of code to another. Swift has 5 control statements

A

Control Transfer Statements

178
Q

Control Transfer Statements (5)

A

Continue
Break
Fallthrough
Return
Throw

179
Q

Continue
(Control Transfer Statement)

A

Tells a loop to stop what it’s doing and start again at the beginning of the next iteration through the loop

180
Q

Break
(Control Transfer Statement)

A

Ends execution of an entire control flow statement immediately.

Thebreakstatement can be used inside aswitchor loop statement when you want to terminate the execution of theswitchor loop statement earlier than would otherwise be the case

                    * Break in a Loop statement
                    * Break in a Switch Statement
181
Q

Fallthrough
(Control Transfer Statement)

A

In Swift,switchstatements don’t fall through the bottom of each case and into the next one. That is, the entireswitchstatement completes its execution as soon as the first matching case is completed

182
Q

Early exit (____): A____ statement, like anifstatement executes statements depending on the Boolean value of an expression.

You use a ____statement to require that a condition must be true in order for the code after the____ statement to be executed. Unlike anifstatement, a____ statement always has anelseclause — the code inside theelseclause is executed if the condition isn’t true

A

guard

183
Q

Model custom types that define a list of possible values

A

Enum

184
Q

If a value (known as a____) is provided for each enumeration case, the value can be a string, a character, or a value of any integer or floating-point type

Clue: Enum

A

rawvalue

185
Q

Enumerations can conform to ____ to provide standard functionality

A

protocols