Random Questions Flashcards

1
Q

What is the MVC?

A

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.

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

What is the difference between a double and a float?

A

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.

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

What is the difference between single equal and double equal?

A

Single equal is for assignment
var isTrue = true
Double equal is for comparison
if isTrue == false { //do this }

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

What is an integer?

A

A whole number that can be negative, positive, or 0

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

How would you convert an int to an Int32? Use 7 (I showed 2 answers)

A

var number: Int32 = 7

Int32(7) → this would convert it.

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

How would you convert an int to a double? var number: int = 7

A

double(number)

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

What is the value of an optional type that has not been assigned a value? var number: Int?

A

Nil

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

How can an if let be used for optionals?

A

It’s a way to see if the optional variable has a value vs being nil

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

What is a stride and how would it be used?

A

Returns the sequence of values

stride(from: 1, to: 10, by: 2)

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

What does concatenating two strings mean?

A
Adding them together 
let newString = "Hello" + " swift lovers"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Does viewDidLoad or viewWillAppear get called first?

A

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.

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

What inherits from what here - Class View: UIViewController { }

A

The class View inherits from UIViewController

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

What is a tuple?

A

Tuples group multiple values into a single compound value.
Let http404error = (404, “Not Found”)
http404error is of type (int, string)

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

What is an optional?

A

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.

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

What is a nil value?

A

A valueless state

If you want to set a value to nil, it has to be optional first

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

What is optional binding?

A

It’s a way to find out if an optional contains a value.
If let contantName = someOptional {
statements
}

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

What happens when you implicitly unwrap something that is nil?

A

Runtime error

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

What is a compound assignment operator?

A

+=

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

What is a ternary conditional operator?

A

It’s a special operator with 3 parts.
Question ? answer1 : answer2
If question is true, then we get answer
Otherwise, we get answer2

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

What is the nil-coalescing operator?

A

a ?? b

This unwraps the optional a if it has a value or returns a default value of b if a is nil

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

What are the 2 ways to initialize an empty string?

A

Var emptyString = “”

Var anotherEmptyString = String()

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

What is string interpolation?

A

“(multiplier)”

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

How would you get the character count of a word?

A

Var word = “cafe”

Word.character.count

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

What are the 3 collection types and describe them?

A

Arrays - ordered collection of values
Sets - unordered collections of unique values
Dictionaries - unordered collections of key value associations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How would you create an empty array of ints?
Var someInts = [Int]()
26
How could you add an integer to variable someInts?
someInts.append(3)
27
When would you need to use a dictionary?
When you need to look up values based on their identities
28
How would you create an empty dictionary called nameOfIntegers of key Ints and string values?
Var nameOfIntegers = [Int: String]()
29
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.
30
What is a while loop? Or was does it do?
It performs a set of statements until a condition becomes false
31
What are the 5 control transfer statements in swift?
Continue, break , fallthrough, return, throw
32
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)
33
What does a break statement do?
A break statement ends execution of an entire control flow statement.
34
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
35
Why do some functions require a return?
They have an arrow indicating a return value
36
What is the return type for a function that has no return type?
``` Func printHelloWorld() { print(“Hello World”) } Void ```
37
What is the structure of a function that has a return type?
``` func nameOfFunction(/* parameters */) -> Type { var valueToReturn: Type // Rest of function return valueToReturn } ```
38
What are properties?
Properties are the values associated with an object | An object's data are “properties”
39
What are methods?
Methods are the functionality associated with an object
40
If you have a struct called Student with values such as name, age, school etc, what you create a variable or a constant with those values, what is that referred to?
``` var ayush = Student(name: "Ayush Saraswat", age: 19, school: "Udacity") Ayush is an instance of student type ```
41
``` var ayush = Student(name: "Ayush Saraswat", age: 19, school: "Udacity") For the above, how would you get the property name ayush? ```
Ayush.name | instanceName.propertyName
42
Where in the application is the natural starting point?
AppDelegate.swift file
43
``` When dealing with functions, show parameter in: Func sayHello(name: String) { } ```
When you right the function (name: String) shows us the parameter name and type
44
``` When dealing with functions, show argument in the function being called: sayHello(name: james) ```
James is the argument
45
What are 2 ways to initialize an empty string?
``` var characterPoorString = "" let stringWithPotential = String() ```
46
How would you initialize an array of Doubles called moreNumbers?
var moreNumbers = [Double]()
47
When you initialize an array as such, let differentNumbers = [97.5, 98.5, 99.0], what is this called?
Array Literal Syntax
48
How would you initialize a dictionary of string, string?
var groupsDict = [String:String]()
49
Explain how the nil-coalescing operator works in this situation: ``` let userDefinedColorName = "green" let defaultColorName = "red" colorNameToUse = userDefinedColorName ??defaultColorName ```
userDefinedColorName is not nil, so colorNameToUse is set to "green”
50
In an enum, what would the raw value of case astros be?
“astros”
51
What does persisting data mean?
Saving or storing the data.
52
What is the plist?
Plist, short for “property list”, is Apple's own data format that makes it easy to store simple data like numbers, strings, and truth values.
53
What is a protocol?
A protocol is a description of functionality that can be adopted—think of it as a contract that a struct or object agrees to fulfill and conform to.
54
Write a protocol called PlayingCard with 2 variables: isFaceDown which is of type Bool and can be settable, shortName which is of type String and is gettable.
protocol PlayingCard { var isFaceDown: Bool { get set } var shortName: String { get } }
55
What is a big difference between classes and structs regarding types?
Classes are reference types | Structs are value types
56
What are some things only classes can do that structs cannot?
Inheritance Type casting Define de-initialisers Allow reference counting for multiple references.
57
What are some of the responsibilities of the UITableViewDelegate and UITableViewDataSource?
UITableViewDelegate - helps row rearranging & editing, determines row height and other row based display concerns UITableViewDataSource - provides the tableview with its contents such as cells, and logic for updating data in the table
58
What is a closure?
A closure is a self-contained block of code that can be passed as an argument to a function.
59
What are 3 ways of going from one vc to another vc?
Code, no segue. You just have 2 vcs. 1 with identifier and it goes to the next vc based on that identifier matching. Segue, no code. Set up a button on vc1 and segue it to the next vc to go to next one just by clicking it Code and segue. You can also set up a button on vc1 to go to vc2 depending on what the identifier is for that segue.
60
What is a delegate?
An object that executes a bunch of methods on behalf of another object Think of a text field delegate, where all the customization code is in the delegate file.
61
What is the difference between searching for a value that doesn’t exist in an array vs dictionary?
In an array, you get an error | In a dictionary, since it is optional, you receive nil.
62
What’s the return type of a function that doesn’t explicitly declare a return type?
Void
63
What is object orientated programming?
We model information into data structures as objects. The objects, like a struct, contain information in the form of stored properties. The pieces of information are tied together under the struct as opposed to just have two random constants outside of a struct. ``` Let x: int Let y: Int Vs. Struct { Let x: int Let y: Int } ```
64
When you have a superclass and you make a subclass, which do you initialize first in the subclass?
You initialize the subclass first
65
What are some differences between structs and classes?
Structs are value types. Which means the values are copied. When we create another instance of something, the values are copied over. Below will have different values if you change it. someStudent.email anotherStudent.email Classes are references types. When we create an instance of a class, the values are references. So if you make an instance and change something for it, they both will have the same changes. Below will have the same exact values! someStudent.email anotherStudent.email
66
When we assign a variable, what is going on behind the scene?
The value is assigned in the memory(Ram), the name simply points to this place in memory where the data lives.
67
What is going on behind the scene when you are creating instance of a struct?
You are making a copy of the previous data and storing it in memory. So you have the original one and then the new one which is a copy. That is why they have 2 different values!
68
What is going on behind the scene when you are creating an instance of a class?
You are not making a copy of anything! You are only referencing whatever has been stored in memory. All instances of the class will point to the same place in memory
69
What are some more examples of value types?
Arrays, Dictionaries, strings, Ints, doubles, booleans
70
TF : A value type is a type whose value is copied when it is assigned to a variable or constant, or when it is passed to a function
True
71
TF : Reference types are not copied when they are assigned to a variable or constant, or when they are passed to a function. Rather than a copy, a reference to the same existing instance is used instead.
True
72
TF : An Int is a value type.
True
73
TF : An Array is a reference type.
False
74
What are the four layers of iOS?
Cocoa Touch Media Core Services Core OS
75
Which of the following types support inheritance? Array, Class, Enum, Struct?
Class
76
TF : When we initialize a subclass, we first need to initialize the properties in our base class, then call the super class' initializer
True
77
TF : Classes are provided with memberwise initializers by default
False
78
Views are instances of the _____ class?
UIView
79
A software _________ is a reusable code base that provides particular functionality in the context of a larger software platform
Framework
80
@IBOutlet weak var funFactLabel: UILabel! → decipher this
@IBOutlet lets xcode know this is an interface builder outlet Weak deals with memory management
81
TF : Refactoring is the process of restructuring code by changing its behavior.
False
82
For each element we need to provide two categories of constraints: _________ and _____________
Position and Size
83
What is a view’s frame?
A rectangle that defines the view’s location and size in it’s superview.
84
What do we use optional binding for?
To see if an optional has a value.
85
What is the purpose of a guard statement?
An early exit or guard statement is a control flow concept where rather than checking for success cases first and worrying about errors last, you deal with the error case up front and exit the current scope.
86
What are the 2 ways to combine 2 strings together?
String Interpolation | String Concatenation
87
TF: A binary value is represented by either a 1 or 2
False. 0 or 1
88
The binary value for true is
1
89
Floating point numbers in Swift are represented by which type
Floats and doubles
90
What is a Unary Operator?
levelScore += 1
91
What is [1] called?
Index value