Random Questions Flashcards
What is the MVC?
Model, View, Controller
MVC allows us to separate the app’s data and logic, the view, and the controller.
The model is the data and logic for the app, while the view is the presentation. The controller’s job is to coordinate between the two to request and deliver data, and help choose a view type.
View is what the user sees and how they interact
Example of a view - Storyboard
Model is for storing the data. (what your app is - but not how it is displayed)
Example of a model - class files, databases, core data.
Controller is in charge of providing the view with data, and the model with any actions. It’s how the Model is presented to the user. (UI Logic)
Example of controller - ViewController.swift files
View has no idea about the data or the model.
What is the difference between a double and a float?
Float is 32-bit while double is 64-bit
Double has a precision of at least 15 decimal digits.
Float has a precision of 6 decimal digits.
So, doubles have double the precision of a float.
What is the difference between single equal and double equal?
Single equal is for assignment
var isTrue = true
Double equal is for comparison
if isTrue == false { //do this }
What is an integer?
A whole number that can be negative, positive, or 0
How would you convert an int to an Int32? Use 7 (I showed 2 answers)
var number: Int32 = 7
Int32(7) → this would convert it.
How would you convert an int to a double? var number: int = 7
double(number)
What is the value of an optional type that has not been assigned a value? var number: Int?
Nil
How can an if let be used for optionals?
It’s a way to see if the optional variable has a value vs being nil
What is a stride and how would it be used?
Returns the sequence of values
stride(from: 1, to: 10, by: 2)
What does concatenating two strings mean?
Adding them together let newString = "Hello" + " swift lovers"
Does viewDidLoad or viewWillAppear get called first?
viewDidLoad - is loaded when your uiviewcontroller is first loaded in memory, even before it is shown on screen.
viewWillAppear - is only presented when view controller is about to be presented on the screen, but before is show on the screen.
What inherits from what here - Class View: UIViewController { }
The class View inherits from UIViewController
What is a tuple?
Tuples group multiple values into a single compound value.
Let http404error = (404, “Not Found”)
http404error is of type (int, string)
What is an optional?
An optional has 2 possibilities, either there is a value, and you can unwrap the optional to access that value OR there isn’t a vale.
What is a nil value?
A valueless state
If you want to set a value to nil, it has to be optional first
What is optional binding?
It’s a way to find out if an optional contains a value.
If let contantName = someOptional {
statements
}
What happens when you implicitly unwrap something that is nil?
Runtime error
What is a compound assignment operator?
+=
What is a ternary conditional operator?
It’s a special operator with 3 parts.
Question ? answer1 : answer2
If question is true, then we get answer
Otherwise, we get answer2
What is the nil-coalescing operator?
a ?? b
This unwraps the optional a if it has a value or returns a default value of b if a is nil
What are the 2 ways to initialize an empty string?
Var emptyString = “”
Var anotherEmptyString = String()
What is string interpolation?
“(multiplier)”
How would you get the character count of a word?
Var word = “cafe”
Word.character.count
What are the 3 collection types and describe them?
Arrays - ordered collection of values
Sets - unordered collections of unique values
Dictionaries - unordered collections of key value associations
How could you add an integer to variable someInts?
someInts.append(3)
When would you need to use a dictionary?
When you need to look up values based on their identities
How would you create an empty dictionary called nameOfIntegers of key Ints and string values?
Var nameOfIntegers = Int: String
Break down the following for loop :
for index in 1…5 {
print(index)
}
The index is a constant value in the range of 1 through 5.
Index is a constant that is implicitly declared.
What is a while loop? Or was does it do?
It performs a set of statements until a condition becomes false
What are the 5 control transfer statements in swift?
Continue, break , fallthrough, return, throw
Describe how continue works.
Continue tells a loop to stop what it is doing and start again at the beginning of the next iteration through the loop (example page 158)
What does a break statement do?
A break statement ends execution of an entire control flow statement.
What does a fall through do?
Fall through is used when there is a case in a switch statement that applies and then if you put fallthrough in that one, it automatically does into the next one
Why do some functions require a return?
They have an arrow indicating a return value
What is the return type for a function that has no return type?
Func printHelloWorld() { print(“Hello World”) } Void