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
Q

How would you create an empty array of ints?

A

Var someInts = Int

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

How could you add an integer to variable someInts?

A

someInts.append(3)

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

When would you need to use a dictionary?

A

When you need to look up values based on their identities

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

How would you create an empty dictionary called nameOfIntegers of key Ints and string values?

A

Var nameOfIntegers = Int: String

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

Break down the following for loop :
for index in 1…5 {
print(index)
}

A

The index is a constant value in the range of 1 through 5.

Index is a constant that is implicitly declared.

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

What is a while loop? Or was does it do?

A

It performs a set of statements until a condition becomes false

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

What are the 5 control transfer statements in swift?

A

Continue, break , fallthrough, return, throw

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

Describe how continue works.

A

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)

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

What does a break statement do?

A

A break statement ends execution of an entire control flow statement.

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

What does a fall through do?

A

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

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

Why do some functions require a return?

A

They have an arrow indicating a return value

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

What is the return type for a function that has no return type?

A
Func printHelloWorld() {
print(“Hello World”)	
}
Void
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is the structure of a function that has a return type?

A
func nameOfFunction(/* parameters */) -> Type {
    var valueToReturn: Type
    // Rest of function
    return valueToReturn
}
38
Q

What are properties?

A

Properties are the values associated with an object

An object’s data are “properties”

39
Q

What are methods?

A

Methods are the functionality associated with an object

40
Q

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?

A
var ayush = Student(name: "Ayush Saraswat", age: 19, school: "Udacity") 
Ayush is an instance of student type
41
Q
var ayush = Student(name: "Ayush Saraswat", age: 19, school: "Udacity") 
For the above, how would you get the property name ayush?
A

Ayush.name

instanceName.propertyName

42
Q

Where in the application is the natural starting point?

A

AppDelegate.swift file

43
Q
When dealing with functions, show parameter in: 
Func sayHello(name: String) {   }
A

When you right the function (name: String) shows us the parameter name and type

44
Q
When dealing with functions, show argument in the  
function being called: sayHello(name: james)
A

James is the argument

45
Q

What are 2 ways to initialize an empty string?

A
var characterPoorString = ""
let stringWithPotential = String()
46
Q

How would you initialize an array of Doubles called moreNumbers?

A

var moreNumbers = Double

47
Q

When you initialize an array as such, let differentNumbers = [97.5, 98.5, 99.0], what is this called?

A

Array Literal Syntax

48
Q

How would you initialize a dictionary of string, string?

A

var groupsDict = String:String

49
Q

Explain how the nil-coalescing operator works in this situation:

let userDefinedColorName = "green"
let defaultColorName = "red"
colorNameToUse = userDefinedColorName ??defaultColorName
A

userDefinedColorName is not nil, so colorNameToUse is set to “green”

50
Q

In an enum, what would the raw value of case astros be?

A

“astros”

51
Q

What does persisting data mean?

A

Saving or storing the data.

52
Q

What is the plist?

A

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
Q

What is a protocol?

A

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
Q

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.

A

protocol PlayingCard {
var isFaceDown: Bool { get set }
var shortName: String { get }
}

55
Q

What is a big difference between classes and structs regarding types?

A

Classes are reference types

Structs are value types

56
Q

What are some things only classes can do that structs cannot?

A

Inheritance
Type casting
Define de-initialisers
Allow reference counting for multiple references.

57
Q

What are some of the responsibilities of the UITableViewDelegate and UITableViewDataSource?

A

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
Q

What is a closure?

A

A closure is a self-contained block of code that can be passed as an argument to a function.

59
Q

What are 3 ways of going from one vc to another vc?

A

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
Q

What is a delegate?

A

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
Q

What is the difference between searching for a value that doesn’t exist in an array vs dictionary?

A

In an array, you get an error

In a dictionary, since it is optional, you receive nil.

62
Q

What’s the return type of a function that doesn’t explicitly declare a return type?

A

Void

63
Q

What is object orientated programming?

A

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
Q

When you have a superclass and you make a subclass, which do you initialize first in the subclass?

A

You initialize the subclass first

65
Q

What are some differences between structs and classes?

A

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
Q

When we assign a variable, what is going on behind the scene?

A

The value is assigned in the memory(Ram), the name simply points to this place in memory where the data lives.

67
Q

What is going on behind the scene when you are creating instance of a struct?

A

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
Q

What is going on behind the scene when you are creating an instance of a class?

A

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
Q

What are some more examples of value types?

A

Arrays, Dictionaries, strings, Ints, doubles, booleans

70
Q

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

A

True

71
Q

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.

A

True

72
Q

TF : An Int is a value type.

A

True

73
Q

TF : An Array is a reference type.

A

False

74
Q

What are the four layers of iOS?

A

Cocoa Touch
Media
Core Services
Core OS

75
Q

Which of the following types support inheritance? Array, Class, Enum, Struct?

A

Class

76
Q

TF : When we initialize a subclass, we first need to initialize the properties in our base class, then call the super class’ initializer

A

True

77
Q

TF : Classes are provided with memberwise initializers by default

A

False

78
Q

Views are instances of the _____ class?

A

UIView

79
Q

A software _________ is a reusable code base that provides particular functionality in the context of a larger software platform

A

Framework

80
Q

@IBOutlet weak var funFactLabel: UILabel! → decipher this

A

@IBOutlet lets xcode know this is an interface builder outlet
Weak deals with memory management

81
Q

TF : Refactoring is the process of restructuring code by changing its behavior.

A

False

82
Q

For each element we need to provide two categories of constraints: _________ and _____________

A

Position and Size

83
Q

What is a view’s frame?

A

A rectangle that defines the view’s location and size in it’s superview.

84
Q

What do we use optional binding for?

A

To see if an optional has a value.

85
Q

What is the purpose of a guard statement?

A

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
Q

What are the 2 ways to combine 2 strings together?

A

String Interpolation

String Concatenation

87
Q

TF: A binary value is represented by either a 1 or 2

A

False. 0 or 1

88
Q

The binary value for true is

A

1

89
Q

Floating point numbers in Swift are represented by which type

A

Floats and doubles

90
Q

What is a Unary Operator?

A

levelScore += 1

91
Q

What is [1] called?

A

Index value