self study Flashcards

(185 cards)

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
This is an example of a: let http404Error = (404, "Not Found")
Tuple
26
Define an alternative name for an existing type and use the keyword ____
Type Aliases typealias
27
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
Optionals
28
If you define an optional variable without providing a default value, the variable is automatically set to ____
nil
29
Trailing question mark
?
30
You must ____ the value of an Optional instance before you can use it in many contexts
unwrap
31
Mention the ways to safely unwrap optional values
*Optional Binding *Optional Chaining *Nil-Coalescing Operator *Force unwrapping / Unconditional Unwrapping
32
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.
Implicitly Unwrapped Optional
33
To conditionally ____ the wrapped value of an Optional instance to a new variable, use one of the optional ____ control sources
bind / binding
34
This safely unwrap optional value, includes: if let, guard let, and switch
Optional binding
35
It’s a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil
Optional Chaining
36
Multiple queries can be chained together, and the entire chain ____ gracefully if any link in the chain is nil
falls
37
Postfix optional chaining operator
(postfix ?)
38
Use the ____ to supply a default value in case the Optional instance is ____
nil-coalescing operator / nil
39
nil-coalescing operator
??
40
When you are certain that an instance Optional contains a value, you can unconditionally unwrap the value by using the ____ operator
force unwrap
41
Forced unwrap operator
(postfix !)
42
Unconditionally unwrapping a nil instance with ! Triggers a ____
runtime error
43
This is an example of a ____ let assumedString: String! = "Hello"
Implicitly Unwrapped Optional
44
Assertions and Preconditions are checks that happen ____, you use them to make sure an essential condition is satisfied before executing any further code.
a runtime
45
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.
true false
46
____ help you find mistakes and incorrect assumption during ____, and ____ help detect issues in ____
Assertions development preconditions production
47
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.
Checked debug debug production
48
in production builds, the condition inside an assertion is evaluated.
No
49
You write an assertion by calling the ____ function

assert(_:_:file:line:)
50
If the code already checks for the condition, you use ____ function to indicate that an assertion has failed
assertionFailure(_:_:file:line:)
51
You write precondition by calling ____ function
precondition(_:_:file:line:)
52
You can also call the ____ function to indicate that a failure has occurred
preconditionFailure(_:_:file:line:)
53
Defines a blueprint of methods, properties, and any other requirements that suit a particular task or piece of functionality
Protocol
54
A protocol defines a ____ of ____ and ____
blueprint methods properties
55
A protocol can be adopted by a ___, ___ and ___
class struct enum
56
Any time that satisfies the requirements of a protocol is said to ____ to that protocol
conform
57
You can ____ a protocol
extend
58
Can multiple protocols be listed?
Yes, separated by commas
59
If a class has a superclass, list a superclass ____ the protocols
before
60
Why do protocols begin with a capital letter?
Because protocols are types
61
Protocol doesn’t specify whether the property should be stored or computed, it only specifies whether each property must be ____, or ____and ____.
gettable gettable settable
62
what is it var mustBeSettable: Int { get set }
A property declared in a protocol
63
Default values, however, can’t be specified for method parameters within a protocol’s definition True or False?
True
64
Protocols can require specific initializers to be implemented by conforming types. protocol SomeProtocol { init(someParameter: Int) } True or False?
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
65
Mutating keyword only applies to ____
structs
66
To force a protocol to be limited to class types only, you can add the ____ protocol to its inheritance list
AnyObject protocol SecretClassFeature:AnyObject {
 func secretClassFeature () 
 }
67
What does the delegation design pattern do?
Enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type
68
delegates are declared as ____ references
weak
69
A protocol can be used as the type to be stored in a collection such as an array or a dictionary? True or False
True
70
A protocol can ____ one or more protocols and can add further requirements on top of the requirements it inherits.
inherit protocol InheritingProtocol: SomeProtocol, AnotherProtocol {

}
71
what is protocol composition?
You can combine multiple protocols into a single requirement You can also create a typealias using protocol composition

 typealias RobotQ = Bipedal & PetrolPowered
72
What are Optional Protocol Requirements? Which is the optional modifier?
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,
73
What are extensions?
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.
74
Extensions can add methods and computed properties, but not ____ properties
stored
75
Assignment operator
=
76
Equal operator
== Returns a boolean
77
+ - * /
Arithmetic Operators
78
%
Reminder or modulo operator
79
+=
Compound operator
80
1...5
Closed Range operator
81
a..
Half Open Range Operator
82
2... or ...2
One-Sided Ranges
83
NOT !a AND ( && ) OR (a | | b  )
Logical Operators
84
Name the logical operators
NOT !a AND ( && ) OR (a | | b  )
85
____ operator appears immediately before their target
Unary prefix !c
86
____ operator appears immediately after their target
Unary postfix c!
87
____ operators operate on two targets, Example: 2 + 3, and are ____ because they appear in between two targets
Binary Operators infix
88
____ operators operate on three targets, ternary conditional operator (a ? b : c)
Ternary
89
String is a ____ type
Value it means that the value is copied
90
What is a String?
A series of characters
91
From which class comes String?
Foundation’s NSString class
92
A ____ is a sequence of characters surrounded by double quotation marks (")
A string literal
93
You can append a character value to a String variable with the String type’s ____ method
append()
94
Can you append a String or Character to an existing Character variable?
No, because a Character value must contain a single character only
95
____ is an international standard for encoding, representing, and processing text in different writing systems
Unicode
96
To retrieve a count of the character values in a string, use the ____ property of the string
count() var word = “cafe”
 word.count()
97
____ property to access the position of the first character of a String
startIndex
98
____ property is the position after the last character in a String
endIndex
99
You can access the indices before and after a given index using the ____ and ____ methods of String
index(before:) index(after:)
100
To access an index farther away from the given index, you can use ____ method
index(_:offsetBy:)
101
To insert a single character into a string at a specified index, use the ____ method
insert(_:at:)
102
To insert the contents of another string at a specified index, use the ____ method
insert(contentsOf:at:)
103
To remove a single character, from a string at a specified index, use ____ method
remove(at:)
104
To remove a substring at a specified range, use the ____ method
removeSubrange(_:)
105
When you get a substring from a string, the result is an instance of ____ not another string
substring
106
Two string values (or two Character values) are considered equal if their extended grapheme clusters are canonically equivalent True or False?
True
107
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
hasPrefix(_:) hasSuffix(_:) Boolean
108
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
mutable immutable can’t
109
Which Collection Type is it? Ordered collection of values
Array
110
Which Collection Type is it? Always zero-indexed
Array
111
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 ____.
runtime error
112
What does the following code do? var emptyArray: [Int] = []
It creates an empty array
113
Write the code to create an empty array:
var emptyArray: [Int] = []
114
Explain the following code: var shoppingList: [String] = [“Eggs”, “Milk”] This is an array ____
literal
115
Why shoppingList doesn't have a type? var shoppingList = [“Eggs”, “Milk”]
Type inferences don’t need to write the type of the array
116
Property to verify if a an arrary is empty?
.isEmpty if shoppingList.isEmpty {
 print("The shopping list is empty."
} else {
 print("The shopping list isn't empty."
}
117
Method to add a new item at the end of the array
append(_:) method You can add a new item to the end of an array by calling the array’s append(_:) method
shoppingList.append("Flour")
118
Retrieve a value from the array by using subscript syntax, passing the ____ of the value
index var firstItem = shoppingList[0]
119
To insert an item into the array at a specified index, call the array’s ____ method:
insert(_:at:)  shoppingList.insert("Maple Syrup", at: 0)

120
You remove an item from the array with the ____ method

remove(at:) let mapleSyrup = shoppingList.remove(at: 0)
121
If you want to remove the final item from an array, use the ____ method
removeLast() let apples = shoppingList.removeLast()
122
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.
enumerated() 
123
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

124
Unordered collection of unique values
Set
125
var letters = Set()
Creating an empty set
126
Coding: Create an empty set
var letters = Set()
127
Design Principles (6)
Aesthetic Integrity Consistency Direct Manipulation Feedback Metaphors User Control
128
Navigation Hierarchy (3)
Hierarchical Flat Content Driven or Experience Driven
129
Navigation Design Guidelines (5)
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
You can remove an item from a set by calling the set’s ____ method
remove(_:) if let removedGenre = favoriteGenres.remove("Rock") {
 print("\(removedGenre)? I'm over it.")
} else {
 print("I never much cared for that.")
}
131
To check whether a set contains a particular item, use the ____ method

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
You can iterate over the values in a set with a ____
for-in loop for genre in favoriteGenres {
 print("\(genre)")
}
// Classical
// Jazz
// Hip hop

133
Swift’s Set type doesn’t have a defined ordering. To iterate over the values of a set in a specific order, use the ____ method
sorted()  for genre in favoriteGenres.sorted() {
 print("\(genre)")
}
// Classical
// Hip hop
// Jazz
134
A ____ stores associations between ____ of the same type and ____ of the same type in a collection with no defined ordering
dictionary keys values
135
Each value is associated with a unique ____, which acts as an ____ for that value within the dictionary
key identifier
136
Unordered collections of key-value associations
Dictionary
137
Code: Create an empty dictionary
var namesOfIntegers: [Int: String] = [:]. //its keys are Int value and its values are of type String
138
You find out the number of items in a Dictionary by checking its read-only ____ property
count  var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"] print("The airports dictionary contains \(airports.count) items.")
139
Use the Boolean____  property as a shortcut for checking whether the count property is equal to 0
 isEmpty
140
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
key var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"] airports["LHR"] = "London"
141
You can also use subscript syntax to ____ the value associated with a particular key
change var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin", "LHR": "London"] airports["LHR"] = "London Heathrow"
142
Remove a key-value pair from a dictionary by assigning a value of ____ for that key
nil airports["APL"] = nil
143
Code: Iterating over a dictionary
for (airportCode, airportName) in airports {
 print("\(airportCode): \(airportName)")
}
144
____ are self-contained chunks of code that perform a specific task
Functions
145
The ____ name is used in the implementation of the function
parameter
146
Type of value that the function takes as input
parameter
147
It’s used when calling the function
Argument
148
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 ____
arguments parameters
149
What does the following mean? Functions with an implicit return
it means that it’s NOT necessary to write the return keyword func greeting(for person: String) -> String {
 "Hello, " + person + "!"
 }
150
Each function parameter has both an ____ label and 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
argument parameter argument parameter parameter
151
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
default value omit
152
Variadic Parameter
(…) 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
In-Out Parameters -> Variadic parameters ____ be marked as inout, &&
can’t
154
____ A function that doesn’t have a return, This is simply an ____, which is written as ____
Void empty tuple ()
155
Function’s signature:
Combination of its name plus its argument names and types, plus its return type
156
Function type =
parameter types + return type
157
Function Parameters are ____ by default.
constants
158
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 ____ parameter instead. ____ parameters can’t have default values, and variadic parameters can’t be marked as inout
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
Nested Functions:
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
____ 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
Methods methods
161
inside a class, structure or enum, are called ____
methods
162
____ are functions that belong to instances of a particular class, structure, or enumeration
Instance methods
163
Structures and enumerations are ____ types. By default, the properties of a ____ type can’t be modified from within its instance methods
 value
164
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
mutating Classes don’t need this keyword in the methods, because are reference type.
165
Control Flow
For-In Loop While Loop repeat-while Conditional statements: If/else Switch
166
To iterate over the items in array, a dictionary to access its key-value pairs, numeric ranges
For-In Loop
167
You can use this syntax to iterate any collection, including your own classes and collection types, as long as those types conform to the ____ protocol.
Sequence
168
Performs a set of statements until a condition becomes false
While Loop
169
These kind of loops are best used when the number of iterations isn’t known before the first iteration begins
While Loop
170
Evaluates its condition at the end of each pass through the loop
repeat-while repeat {
 <#statements#>
 } while <#condition#>
171
Conditional statements:
If/else Switch
172
Considers a value and compares it against several possible matching patterns Clue: it's a conditional statement
switch
173
Every switch statement must be ____
exhaustive
174
____: A switch case 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
Value bindings
175
A switch case can use a ____ clause to check for additional conditions
where
176
____: Multiple switch cases that share the same body can be combined by writing several patterns after case. ____ can also include value bindings
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
____: Change the order in which your code is executed, by transferring control from one piece of code to another. Swift has 5 control statements
Control Transfer Statements
178
Control Transfer Statements (5)
Continue Break Fallthrough Return Throw
179
Continue (Control Transfer Statement)
Tells a loop to stop what it’s doing and start again at the beginning of the next iteration through the loop
180
Break (Control Transfer Statement)
Ends execution of an entire control flow statement immediately. The break statement can be used inside a switch or loop statement when you want to terminate the execution of the switch or loop statement earlier than would otherwise be the case * Break in a Loop statement * Break in a Switch Statement
181
Fallthrough (Control Transfer Statement)
In Swift, switch statements don’t fall through the bottom of each case and into the next one. That is, the entire switch statement completes its execution as soon as the first matching case is completed
182
Early exit (____): A ____ statement, like an if statement 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 an if statement, a ____ statement always has an else clause — the code inside the else clause is executed if the condition isn’t true
guard
183
Model custom types that define a list of possible values
Enum
184
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
raw value
185
Enumerations can conform to ____ to provide standard functionality
protocols