IOS Fundamentals & Data Persistence Flashcards

1
Q

What are apps?

A

Apps are bundles of files, they’re individual items held together in a file and bundled.

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

What does swiftUI get rid of?

A

Storyboards

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

What is complied code that makes up an app formed of?

A
  • Unique code
  • frameworks
  • info.plist configuration file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do we get resources in IOS such as images, sounds etc?

A

By using asset libraries

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

When you create a swift program what does xcode automatically generate?

A

xcode automatically generates the basic files for a project of the selected type

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

Which file does main typically reference?

A
  • AppDelegate.swift as this is the main entry point for your application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the two functions of the AppDelegate.swift source file?

A
  1. to create an entry point and run loop for your app (equiv to main() in programs)
  2. defines AppDelegate class which is the blueprint for an app. It creates window where app content is drawn. You write your custom app level code here
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the app delegate do when you go into another app on your phone?

A

It keeps the previous app running in the background as it may need to complete some tasks/it may have more processing to do, such as storing information, before it completely terminates.

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

What is a Delegate?

A

code that provides some additional functionality by providing specific methods, which can be invoked when required by another class.
- Apple asks your delegate to do things on your behalf because it can only provide so much functionality. Your app is original, so you have to define what’s original about it by customising your delegate code.

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

What is an app Delegate?

A
  • A single delegate object that provides specific methods to handle events that occur as part of the lifecycle of an App
  • E.g. your App starting up. Your App’s window contents being drawn on the screen. Your App closing down. etc…
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the ViewController.swift do?

A

This stores all the information about what’s displayed in our app

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

What type of code is placed in ViewController.swift

A
  • IBOutlets (labels etc.) and IBActions (buttons)
  • Class and Structure names start with A-Z
  • Method names start a-z
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is UIKit?

A
  • It defines the core components of an iOS application
  • it’s specific to iOS (can’t be used for macOS for example)
  • most UIKit classes can only be used from the app’s main thread
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is iInside a Swift iOS app

A
  • It has a series of states pre-defined, those are still there but they have been moved to another file
  • When you tap on an app on your phone, the process moves into the foreground
  • When you then go into another app, the process transitions into the background, and finishing doing the processing it needs to before being suspended/terminated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is delegation?

A

A design pattern where a host object embeds a “pointer” to another object (the delegate), and sends messages when input etc is required

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

What are the two required methods used in a tableView?

A
  • number of rows
  • number of sections in the table (if you don’t provide this it has a default of 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how does swift save memory and processing time when implementing tableViews?

A

Swift only draws out as many items as are visible on the screen to save memory space/processing time
- When the items we first drew up are no longer visible on the screen, they are disregarded.
-When tables are drawn, only the content on the screen is required from the delegate.

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

What are views?

A

they are rectangular areas on screen that handle events and display content

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

What are viewControllers?

A

They are special controllers that manage views?

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

What does the UIKit framework do?

A
  • It defines the main layer of classes an application needs to construct and manage it’s interfaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are touch events?

A
  • When the user touches the screen
  • could be touchesBegan, touchesMoved, touchesEnded, touchedCancelled
  • Touch events are a whole series of touch movements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does the UIGestureRecogniser do?

A

It allows you to detect very gentle touches/motion on the screen such as a long press, a double tap or a swipe

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

What does the Navigation Bar allow you to do?

A
  • Allows you to progress through a structure, giving more specific related detail on every next step of the hierarchical structure. For example Settings in IPhone.
  • They use the screen the most effectively by hiding complexity from the user. Too many options on the page may confuse them.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does the search Bar allow you to do?

A
  • Used to search through a large collection of values
  • prominent or minimal styles
  • minimal search bars don’t expand until tapped on
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does the tab Bar allow you to do?

A
  • at the bottom of the screen
  • quickly switch between sections
  • tabs hide complexity
  • no hierarchy between tabs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the toolbar allow you to do?

A
  • at the bottom of the screen
  • buttons for performing actions
  • used for performing actions relevant to what’s displayed on the screen.
  • no hierarchy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What do action sheets allow you to do?

A
  • specific alert (like delete photo or keep photo)
  • Used when we need the user to make a choice (and we may want to warn then about the choice they’re making)
  • These are generated dynamically so you choose how many options are provided
  • It’s better not to include too many options that will confuse/overload the user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the MVC Design pattern?

A

The model, view controller design pattern classifies objects according to the role they play in the app.
- code is more reusable due to this because it minimises dependencies, you can take a model or view class you’ve already written and use it elsewhere

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

What are model objects?

A

They encapsulate data and basic behaviour (data hiding)

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

What are view objects?

A
  • What the user looks at
  • presents information to the user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What are controller objects

A

Controller objects tie the model to the view

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

What is the role of the controller?

A
  • it’s the code that connects the model with the view components as these two are unware of each other’s existence
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Where do we write in / put most of our code

A

The view controllers

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

Describe the model component

A
  • Contains your underlying data and object model
  • actions on the model manage the app data and it’s state
  • not reliant on an interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Describe the view component

A
  • What you see on the user interface
  • does not store any data
  • the canvas itself, place buttons, labels and other views on it
  • view controller can be used to update the model component
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Describe the controller component

A
  • handles information flow between the model and the view components
  • when the model changes it lets the view know
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Why is the controller in a MVC rarely reusable?

A
  • Because they’re typically app specific
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What are outlets?

A

They allow your code to access the value of interface objects

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

How are views typically arranged?

A
  • In a hierarchical structure
  • every view has one superview
  • every view has zero or more subviews
  • views live inside of a window UIwindow)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is a UIResponder

A

UIResponder is something that can respond to an event

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

What is flipped in view related structures?

A

The coordinate system is flipped - (0,0) is in the top left corner instead of bottom left
- So x and y increase as you go downwards
- You can type coordinates in as you usually would however as the OS automatically flips them for you

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

What is the difference between frame and bounds?

A

Frame is the location within the enclosing view
Bounds i.e. the origin on whether the frame or the bound system is used

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

How do you decide whether to use frames or bounds?

A

Depending on the context
- if using a view (storyboard function) use bounds
- if implementing a view (coding in the view controller) use frames

44
Q

Why should you not try to run saved versions of graphics instead of having them redrawn when the program is run?

A
  • what’s on the screen changes constantly so if you try to run a saved versions it’s most likely wrong/out of date with the current system
45
Q

What are IBOutlets?

A

Properties of a view controller that are exposed to storyboard
- objects created in storyboard, memory for these objects is allocated
- by linking objects to the view controller. the controller can control these objects

46
Q

What are IBActions?

A
  • These identify methods provided by the view controller that can be called when some action occurs on the user interface
  • linked to objects with outlets, can change state of program
47
Q

How can we define the size and location of view objects?

A
  • using storyboard: drag them onto view and change to desired size
  • programatically: type in size and location in UIViews initialiser method
48
Q

What is storyboard?

A

It allows you to design apps
- allows developer to see a top-down view of all the view controller interfaces

49
Q

What are scenes and segues?

A
  • scenes are what is on the screen the page)
  • segues are the transitions between views (scenes)
50
Q

What is SwiftUI?

A

a framework for creating apps on multiple platforms

51
Q

Why might we use swiftUI over UIKit?

A
  • It’s very fast in comparison
  • swiftUI is GPU accelerated. So the view hierarchy is flattened and swiftUI ignores unnecessary parts that it knows won’t be used so it runs quickly and efficiently.
52
Q

What does it mean that switUI is declarative?

A
  • SwiftUI is declarative meaning that we specify for all the variables what should happen
  • Then swiftUI tracks the state of each variable and updates the interface for us
53
Q

What are controls?

A

They are view objects that allow users to initiate some type of action
- they respond to a variety of events such as touch events, value changes, editing events

54
Q

What does it mean that controls are target/action

A
  • When an event occurs and action is invoked on the target object
55
Q

What does sender correspond to in action methods?

A

The object that created the event

56
Q

How can we implement that the same event controls multiple action on different targets in response to the same event?

A
  • We can link multiple methods to the same button
57
Q

What are the 4 methods linked to touch events?

A
  • touchBegan
  • touchesMoved
  • touchesEnded
  • touchesCancelled
58
Q

Why is it important to override initial methods for an event?

A
  • so that we don’t allow events to “escape” and for actions to be based on them instead of what we actually want
59
Q

What do we do when we create a new view in storyboard?

A
  • We need to create a new cocoa touch class source file
  • so we can place links to IBOutlets and IBActions in it
  • then we must link the view inside storyboard by selecting the new class file
60
Q

What do we use to go from one view controller to another?

A

Transitions known as segues
- which we can define in storyboard

61
Q

What is the default segue?

A
  • Swipe down to go back to the previous scene
62
Q

What do we use an unwind segue for?

A
  • add an unwind segue so we’re not just overlaying view controllers and it gives the appearance of swiping down to go back to the last scene
63
Q

How do we pass data between views?

A
  • One option is to declare a global variable
    however this is not liked so we pass information through segues
64
Q

What do UINavigatonControllers do?

A
  • They provide a stack of controllers, so that as the user explores the data in new views corresponding controllers are pushed onto the stack
  • UIKit automatically names the next view controller with the previous title.
  • We can program this ourselves manually but there’s no need when storyboard does it
65
Q

What are the two main methods in swift used to change the content of a navigation stack by the program?

A
  • push to add a view controller
  • pop to remove a view controller
66
Q

Describe how tab bar controllers work?

A
  • Have a flat relationship (no hierarchical structure)
  • all tabs are stored in an array
  • view controllers can define their appearance in the tab bar (by customising their icon)
67
Q

What happens when a tab bar has too many view controllers to display?

A

it adds a “More” tab bar item
- user can navigate to remaining view controllers
- user can also customise what appears on the tab bar

68
Q

if we combine a navigation bar and a tab bar what order should we create them in?

A
  • create tab bar controller first
  • then create navigation controllers
  • finally add them to the navigation controller
69
Q

What are modal views used for?

A
  • often used to gather new data or present information
  • displaying preferences, asking user for specific information to create a new contact for instance
  • presenting alerts or action sheets
70
Q

What happens when a modal view is presented

A
  • a parent-child relationship is created between
71
Q

Which is the child and which is the parent in a parent-child relationship with modal views?

A
  • the view controller doing the presenting is the child
  • the view controller managing the modal view is the parent
72
Q

How do you present a view controller modally

A
  1. Create the view controller you want to present
  2. Set the modalTransitionStyle property of the view controller
  3. Assign a delegate object for the modal view controller
  4. Call presentViewController(_ viewControllerToPresent:
    UIViewController, animated flag: Bool, completion: (() -> Void)?
    = nil) method of the view controller parent, passing in the view controller child
73
Q

What are the two ways modal views can appear (transition semantics)

A
  1. Sheet
  2. Full screen
74
Q

How do we dismiss a Modal View Controller

A
  • best approach is to let the parent dismiss it’s own child view controller
  • the child view controller must define a protocol for its delegate to implement
  • this defines actions the parent should do in response to certain actions
75
Q

What are the advantages of having the parent of the modal view dismiss it’s own child?

A

*Allows the parent to validate data before dismissing the child
*Promotes reuse, as the child view controller can be reused elsewhere

76
Q

What is a protocol?

A
  • a list of methods, properties and other requirements that can be shared among classes
77
Q

How does the parent of the modal view it’s presenting know when to dismiss it’s child?

A
  • The child sends a message to their parent telling them to do so, via a protocol that tells the child this is what they need to do
78
Q

What are some of the reasons we may want to store data in persistent storage?

A
  • Storing preferences
  • storing simple data in general
  • storing state of program (to be recovered)
  • managing data
79
Q

What must apps do if they want to include data in the bundle (of files that make up the program) that can later be modified?

A
  • they must copy the data into it’s documents directory
  • then the data can be modified
  • we mark the data as excluded from backup
  • only copy data on first use
80
Q

What would happen if you modified an app’s bundle?

A
  • then the app signature would become invalid, and the app would fail
  • so every app has a private writable file system
81
Q

What URL do you use to get to the Application’s (read-only) bundle directory

A

Bundle.main
-Bundle contains both individual files, and can also contain folders

82
Q

What can we use to allow users to add and delete files directly to an application?

A
  • iTunes File sharing: Applications can expose files in their (writeable) Documents directory to iTunes (when syncing)
83
Q

What are property lists?

A
  • Property lists are structured data used by Foundation, typically XML-based data format
  • Provides support for Primitive data types and collections
84
Q

What is a good method for storing small structured persistent data fragments?

A

property lists

85
Q

What are property lists good for storing?

A

Good for:
*less than a few hundred kilobytes of data
*well defined data elements, that fit the XML data
serialisation

86
Q

What are property lists bad for storing?

A

Bad for:
*Large data volumes
*Loading is “one-shot”
*Complex objects
*Blocks of binary data

87
Q

When are user defaults used as persistent storage?

A

*Often applications need to save a small number of settings e.g. preferences or last used settings
*UserDefaults provides a “registry” for storing values
*Generated on a per user / per application basis
*Register the different settings
*Determines the default values and types of the settings for first use, or if reset
- stores data to a database

88
Q

Why are user defaults useful?

A
  • They can be set and retrieved at any point in the application
89
Q

What is JSON

A

JavaScript Object Notation is an open standard file format that uses human-readable text to transmit
data objects

90
Q

What does JSON look like?

A

The JSON structure naturally matches that of the Swift types:
* Dictionaries that contain key-value pairs
* Arrays or Sets that contain lists of values
* (and their bridged Foundation equivalents, NS…)

91
Q

How do we load complex data from JSON

A

*The JSONSerialization mechanism produces a single object that you have to carefully navigate through to access the items you want
*It requires casting inner items into their appropriate types
*but this is Error prone and messy

92
Q

What is the more reliable method for encoding and decoding JSON complex data?

A

Encoding and Decoding using the codeable protocol

93
Q

What is serialisation (archiving objects)?

A
  • A serialisation of some object graph that can be saved to disk and then be loaded later
  • Use the Encodable and Decodable protocols
  • Declares two methods that a class must implement so that instances can be encoded or decoded
94
Q

What is core data?

A

A schema-driven object graph management and persistence framework
*Model objects can be saved to the file store and then retrieved later

95
Q

What does core data provide?

A

*provides an infrastructure for managing all the changes to your model objects
*supports the management of a subset of data in memory at any time
*Good for managing memory and keeping the footprint low
*uses a diagrammatic schema to describe your model objects and relationships
*maintains disjoint sets of edits on your objects so can allow the user to edit some of your objects, whilst displaying them unchanged elsewhere

96
Q

What is the Core Data Stack

A

A collection of Core Data framework objects that access a persistent store *Could be a database, doesn’t have to be.

97
Q

How does Core Data hide complexity from the user?

A

Core Data allows the developer to manage data at the top of this stack
*abstracts away the storage mechanism
*Allows the developer to focus on
*Managed Objects (i.e. records from tables in databases)
*Managed Object Context (i.e. work area which manages objects from a Core Data store

98
Q

What are managed objects?

A

An object representation of a record from a table in a database
- The data used within the application
*shapes, lines, groups of elements in a drawing program
*artists, tracks, albums in a music database
*people and departments in a HR application

99
Q

What is a managed object context?

A

A context represents a single object space in an application

100
Q

What are managed object contexts responsible for?

A

Responsible for managing a collection of Managed Objects
*Managed objects form a group of related model objects that represent an internally consistent view of a data store *e.g. records and their relationships

Also responsible for:
*the complete life-cycle management
*validation of data
*relationship maintenance
*Undo and Redo of actions

101
Q

What happens if something hasn’t been committed to the database

A
  • a change to a managed object will not be written into the database
102
Q

What does a managed object model represent?

A

It represents a schema that describes the data (and hence the database)
*And hence the managed objects in the application
*A model is a collection of entity description objects

*Describes an entity or table in a database, in terms of:
*Its name
*Name of the class used to describe the entity in the app
*Its properties and attributes

103
Q

What does core data use the managed object model to do?

A

It uses the model to map between managed objects in your app to records in the database

104
Q

what do you select when creating the project in which you want to use core data?

A

Select “Use Core Data”
- Includes additional code within the app delegate
implementation file
*Manages files in the applications Documents Directory
*Provides a persistent store coordinator for the app
*Returns the managed object model for the app
*Also provides the managed object context for the app

105
Q

What is a data model?

A

a collection of entity and property
description objects that describe the Managed
Objects
* This model can be described programmatically
* Entities can be added to the model
* Attributes can then be defined

106
Q

How does core data make efficient use of when accessing the disk?

A

-To fetch objects you need a managed object context and a fetch request.
- Often, objects not directly fetched, but that are relevant to it (related objects being fetched) will also be retrieved at the same time to save having to look for them again when they are needed

107
Q

Data Persistence - Summary

A

*There are a number of mechanisms for storing and retrieving persistent data in iOS
*The mechanism you use depends on the type and amount of data
*Use UserDefaults where there are relatively simple, small amounts of data
*App Bundle and filesystem is particularly suited to file-based items e.g. audio, images and video (App bundle is read-only, App filesystem is read/
write)
*Core Data is database-like and ideal for large amounts of structured data