iOS General Flashcards

1
Q

What states can a running UIApplication be in?

A

UIApplicationState: Active, Inactive, and Background

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

What classes would you use to encode and decode NSCoding compliant classes into a format that can be stored in a file?

A

NSKeyedArchiver and NSKeyedUnarchiver

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

What is the C-based API for concurrent programming?

A

Grand Central Dispatch

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

What is the object oriented API for concurrent programming?

A

NSOperation (and NSOperationQueue)

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

How many view controllers does a UISplitViewController manage?

A

Either one (if it is collapsed) or two

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

What is the main limitation when using Objective C categories?

A

A category cannot define new instance variables or add new storage to a class

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

Name a common cause of exc_bad_access

A

Trying to access an object that has been released (or not initialized)

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

Name a common way of tracking down the cause of exc_bad_access

A

Enable zombie objects within the Xcode scheme

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

What do you need to do in a project to use Swift from Objective C?

A

Xcode creates a ‘generated header’ automatically, you just need to import it

(But note that classes need to extend NSObject or be marked with the @objc attribute in order to be available to Objective C - and of course don’t expose things like tuples, that only exist for Swift)

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

What do you need to do in a project to use Objective C from Swift?

A

Create a ‘bridging header’ that imports the required code

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

Does a delegating object maintain a strong or weak reference to its delegate?

A

Weak

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

What is the Swift equivalent of Objective C categories?

A

Extensions

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

What is a workaround for categories not being able to add new instance variables to a class?

A

Use ‘Associated Objects’ via objc_[set,get]AssociatedObject

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

Which Foundation collection would you use for frequent containsObject: tests?

A

NSSet (it’ll be faster than NSArray)

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

What is required of classes that are to be used as dictionary keys?

Provide answers for both Objective C and Swift

A

Objective C: they must conform to NSCopying and implement copyWithZone:

Swift: they must conform to Hashable and implement var hashValue: Int { get }

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

What is a key requirement when implementing the isEqual: method?

A

If two objects are equal, they must have the same hash value

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

When would you use __block?

A

Normally variables are copied when used inside a block and so changes are not reflected outside of the block - but when using __block, such changes are visible outside too

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

What is a retain cycle?

A

A retain cycle is a situation when object A retains object B, and object B retains object A at the same time (there could be longer chains of objects too)

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

Explain messages vs methods in Objective C

A

Sending messages is more dynamic. Sending a message usually results in the corresponding method being called - but it doesn’t have to. Objects don’t have to respond to messages. Messages that an object responds to don’t have to be known at compile time

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

Name a way to add visual effects (such as blur or vibrancy) to a user interface

A

Using a UIVisualEffectView in conjunction with UIBlurEffect or UIVibrancyEffect

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

What’s the difference between UIModalPresentationFullScreen and UIModalPresentationOverFullScreen?

A

FullScreen removes the views beneath the presented view controller, whereas OverFullScreen does not (and hence they may still be visible in some form)

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

When would you use NSValue?

A

When you need to wrap scalar types - e.g. ints, floats, chars, pointers, structs, object id references - in an object (so that they can be added to a collection, for example)

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

When is a view controller’s preferredContentSize generally used?

A

When displaying the view controller’s content in a popover

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

How do you determine which view controller presented a view controller (if any)?

A

Use the UIViewController property presentingViewController

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

Should you call dismissViewControllerAnimated:completion: on the view controller you wish to dismiss, or the view controller that presented it?

A

The view controller that presented it

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

Name a built in way of evaluating a string containing an arithmetical expression such as “1 + 2 + 3”

A

NSExpression

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

Name a built in way of evaluating a string containing a logical expression such as “1 + 2 > 2”

A

NSPredicate

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

Name the logical drawing space used by native drawing technologies such as Quartz, UIKit, and Core Animation (i.e. not pixels!)

A

Points

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

State the difference and relationship between points and pixels

A

Points are logical whereas pixels are physical.

The system automatically maps points in the view’s coordinate space to pixels in the device coordinate space, but this mapping is not always one-to-one.

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

State the logical resolution of an iPhone 4

A

320 x 480 (points)

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

State the logical resolution of an iPhone 5

A

320 x 568 (points)

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

State the logical resolution of an iPhone 6

A

375 x 667 (points)

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

State the logical resolution of an iPhone 6 plus

A

414 x 736 (points)

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

State the logical resolution of an iPad

A

1024 x 768 (points)

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

What is the superclass of UIView?

A

UIResponder

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

What is the superclass of UIApplication?

A

UIResponder

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

What is the superclass of UIResponder?

A

NSObject

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

What is the superclass of UIWindow?

A

UIView

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

What does it mean for a UIWindow to be a key window?

A

The key window is the one that is designated to receive keyboard and other non-touch related events

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

How many UIWindows can be the key window at any time?

A

Only one window at a time may be the key window

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

How do you get a UIApplication’s key window?

A

Via its keyWindow property

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

In general, how many UIWindows does an iOS app have?

A

Generally just one. However it is possible for an app to have more than one window (especially if it can display content on an external screen).

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

How do you get references to an application’s windows?

A

Via the windows property that UIApplication instances have.

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

How do you get the singleton UIApplication instace for your app?

A

UIApplication.sharedApplication()

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

What is a window’s root view controller? (As per the UIWindow rootViewController property)

A

The root view controller provides the content view of the window. Assigning a view controller to this property installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.

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

How do you get a window’s root view controller?

A

Via the rootViewController property on UIWindow instances

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

How do you get a view controller’s navigation controller (if there is one)?

A

Via the UIViewController navigationController property

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

What is the superclass of UIViewController?

A

UIResponder

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

How do you get a view controller’s split view controller (if there is one)?

A

Via the UIViewController.splitViewController property

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

How do you get a view controller’s tab bar controller (if there is one)?

A

Via the UIViewController tabBarController property

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

How would you determine the best size of a UIView considering all constraints it holds and those of its subviews?

A

Using systemLayoutSizeFittingSize() and passing it one of:

UILayoutFittingCompressedSize
UILayoutFittingExpandedSize

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

When considering a UIView’s subviews array, how does placement in the array affect the visible order on the screen (z order)?

A

The view at index 0 is the back-most view. The view at the highest index is the front-most view.

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

When considering the Interface Builder document outline, how does the vertical placement of views in the list relate to their z ordering?

A

The item at the top of the list is the back-most view. The item at the bottom of the list is the front-most view.

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

How do you get your application’s documents directory?

A

By passing the values NSDocumentDirectory and NSUserDomainMask to the NSFileManager method URLsForDirectory:inDomains:

This method returns an array of URLs - but on iOS there’s only ever one element in the array.

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

Where should you store files on disk that you want to be persisted and backed up?

A

In the application’s documents directory

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

Name the enumeration that represents the types of directories you may wish to access from an app (for example, the documents directory or caches directory)

A

NSSearchPathDirectory

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

Give a very rough outline of a strategy for having a popover on an adapting to a modal with navigation on iPhone

A
  1. Setup popover presentation segue without nav con
  2. In prepareForSegue set a delegate on the dest VC’s popoverPresentationController
  3. Use delegates’ presentationController:viewControllerForAdaptivePresentationStyle to return a nav con
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

How do you get a view controller’s popover presentation controller (if there is one)?

A

Using UIViewController’s popoverPresentationController property

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

In a navigation controller’s viewControllers array, at which index is the root view controller?

A

Index 0

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

In Core Data, what is the name of the resource that contains the definition of an application’s data structure / schema?

A

The Managed Object Model

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

In Core Data, what is the name of the resource that contains the applications data (for example, the SQLite database)?

A

The Persistent Store

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

In Core Data, what is the name of the object that mediates between Persistent Store(s) and Managed Object Context(s) as per the Managed Object Model?

A

The Persistent Store Coordinator

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

Describe what a Managed Object Context is

A
  • Single object space / scratchpad
  • Manages a collection of managed objects
    • (Internally consistent view of 1+ persistent stores)
    • Fetching, creating
  • Undo / redo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

Can a managed object context have more than one managed object that represents a given record in a persistent store?

A

No - there can only be one

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

Describe what faulting means, with reference to Core Data

A

A fault is a placeholder object that represents a managed object that has not yet been fully realized, or a collection object that represents a relationship:

  • Managed object: an instance of the appropriate class (persistent variables are not yet initialized)
  • Relationship: a subclass of the collection class that represents the relationship
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

Describe uniquing, with reference to Core Data

A

Uniquing ensures that, in a given managed object context, an entry in a persistent store is associated with only one managed object.

Without uniquing, you could end up with a context maintaining more than one object to represent a given record (and they could contain different and conflicting data).

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

What class would you use to parse decimal strings, currency strings, etc into numbers?

A

NSNumberFormatter. Here’s an example of parsing a French-style decimal in Swift:

let formatter = NSNumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "fr")
let number = formatter.numberFromString("1,34")

// number == 1.34

68
Q

If your app has a settings bundle (i.e. uses the main iOS Settings app), where are the user settings stored?

A

In your app’s NSUserDefaults

69
Q

What is a plist?

A

A property list is a structured data representation used by Cocoa and Core Foundation as a convenient way to store, organize, and access standard types of data

70
Q

What types of data can comprise a plist?

A
  1. array (NSArray)
  2. dictionary (NSDictionary)
  3. string (NSString)
  4. data (NSData)
  5. date (NSDate)
  6. number - integer (NSNumber)
  7. number - floating point (NSNumber)
  8. Boolean (NSNumber)

Note that Core Foundation (CF*) equivalents of the above can also be stored.

71
Q

How would you store an instance of a custom class in a plist?

A
  1. Have the class conform to NSCoding
  2. Use a NSKeyedArchiver to convert objects of your class to NSData
  3. The NSData can then be natively stored in the plist
72
Q

What are the required methods when conforming to the NSCoding protocol?

A
  • (id)initWithCoder:(NSCoder *)decoder
  • (void)encodeWithCoder:(NSCoder *)encoder
73
Q

What protocol would you conform to when you want your classes to be able to be encoded and decoded (and archived and unarchived)?

A

NSCoding

74
Q

Describe the NSCopying protocol. Name one notable case where classes are required to implement it.

A

The NSCopying protocol declares a method (copyWithZone:) for providing functional copies of an object. The meaning of “copy” can vary from class to class, but a copy must be a functionally independent object with values identical to the original at the time the copy was made.

Notable case: objects used as NSDictionary keys must conform to NSCopying.

75
Q

What types of data can you store in NSUserDefaults?

A

Property list (plist) types:

  1. array (NSArray)
  2. dictionary (NSDictionary)
  3. string (NSString)
  4. data (NSData)
  5. date (NSDate)
  6. number - integer (NSNumber)
  7. number - floating point (NSNumber)
  8. Boolean (NSNumber)

Note that Core Foundation (CF*) equivalents of the above can also be stored.

76
Q

Briefly explain the difference between Foundation and Core Foundation

A

Foundation is an Objective-C API, which provides NSString, NSDictionary, etc.

Core Foundation is a C API, which provides CFString, CFDictionary, etc.

77
Q

Describe what the following function does:

UIApplicationMain(argc, argv, principalClassName, delegateClassName)

A

This function is called to:

  1. Create the application object
  2. Create the application delegate
  3. Set up the main event loop, including the app’s run loop, and begins processing events
  4. Load any main nib/storyboard
78
Q

The function UIApplicationMain() has a return type of int - but what does it return?

A

Nothing - the function never actually returns

RR: the return type of int is most likely used to fit in with C’s main() function, from where UIApplicationMain() is called

79
Q

Explain Deployment Target and Base SDK

A

Deployment Target: the oldest version of iOS you’re supporting

Base SDK: the newest version of iOS you’re supporting (this setting will generally be “Latest iOS”)

80
Q

What is a run loop?

A
  • A run loop is an event processing loop (e.g. a WHILE) that you use to:
    • Schedule work
    • Coordinate incoming events
  • Every thread has an associated run loop object (including the application’s main thread)
  • Keeps the thread busy when there is work to do and puts it to sleep when there is none
81
Q

When would you use a run loop?

A

The only time you need to run a run loop explicitly is when you create secondary threads for your application.

The run loop for your application’s main thread is a crucial piece of infrastructure. As a result, the app frameworks provide the code for running the main application loop and start that loop automatically.

82
Q

Describe the main queue (or “main dispatch queue”)

A
  • Globally available
  • Serial queue
  • Executes tasks on the application’s main thread (and so is a key synch point for an app)
  • Works with the application’s run loop to interleave execution of queued tasks with execution of other event sources attached to the run loop
83
Q

List the types of dispatch queue

A
  1. Serial (tasks executed one at a time)
  2. Concurrent (tasks executed concurrently)
  3. Main dispatch queue (globally available serial queue)
84
Q

Describe the main event loop

A
  • Run loop for the main thread
  • App continuously routes incoming events to objects for handling and, as a result, updates its appearance and state
  • Its primary input source receives events from the OS that are generated by user actions (e.g. tapping a view)
85
Q

Describe LLVM

A

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines.

LLVM is an alternative to (say) GCC.

Clang is a C/C++/Objective C “front end” to LLVM. Swift uses LLVM too.

86
Q

Describe Clang

A

Clang is a C, C++, Objective C and Objective C++ front-end for the LLVM compiler.

(Also: Clang has the Clang Static Analyzer, a source code analysis tool that finds bugs in C, C++, and Objective-C programs, which can be used from within Xcode)

87
Q

Describe LLDB

A

The LLDB project builds on libraries provided by LLVM and Clang to provide a native debugger.​

LLDB is the default debugger in Xcode on Mac OS X and supports debugging C, Objective-C and C++ on the desktop and iOS devices and simulator.

Swift uses LLDB too.

88
Q

Describe the Objective-C Runtime

A

The Obj-C Runtime is a library that adds object oriented capabilities to C to create Obj-C. It essentially creates all the support structures that make OOP with Obj-C possible.

Importing runtime.h lets you interact with the runtime via C calls, but Foundation provides a some access for Obj-C too.

What can you do with it? All sorts of things from checking if a class responds to a selector to dynamically generating classes at runtime.

89
Q

What framework would you use for accessing and manipulating calendar events and reminders?

A

EventKit

90
Q

What is the relationship between Quartz 2D and Core Graphics?

A

The Quartz 2D API is part of the Core Graphics framework, so you may see Quartz referred to as Core Graphics or, simply, CG.

91
Q

Give an overview of the layers in iOS from the Core OS up to Cocoa Touch

A
  1. Cocoa Touch
  2. Media
  3. Core Services
  4. Core OS
92
Q

Describe the Cocoa Touch layer in iOS

A

The Cocoa Touch layer includes k​ey frameworks for building iOS apps, including:

  • UIKit
  • MapKit
  • EventKit UI
  • Message UI
93
Q

Describe the Media layer in iOS

A

The Media layer contains the graphics, audio, and video technologies you use to implement multimedia experiences in your apps, including:

  • Core Graphics
  • Core Animation
  • Core Image
  • Core Text and TextKit
94
Q

Describe the Core Services layer in iOS

A

The Core Services layer contains fundamental system services for apps, including:

  • Core Foundation and Foundation
  • Core Data
  • Core Motion
  • Core Location
  • EventKit
95
Q

Describe the Core OS layer in iOS

A

The Core OS layer contains the low-level features that most other technologies are built upon. Even if you do not use these technologies directly in your apps, they are most likely being used by other frameworks. Frameworks include:

  • “System”
  • Core Bluetooth
96
Q

Describe the class cluster pattern

A

Class clusters group a number of private concrete subclasses under a public abstract superclass.

The grouping of classes in this way provides a simplified interface to the user, but behind the scenes, the abstract class is calling up the private subclass most suited for performing a particular task.

Eg. depending on how you get hold of an NSString, it could actually be one of several private subclasses.

97
Q

Name the two most common subclasses of NSCoder

A

NSKeyedArchiver and NSKeyedUnarchiver

98
Q

Describe target-action

A

Target-action is a mechanism for communication between a control and another object.

The control holds the information necessary to send a message to another object when an event occurs. This information consists of two items:

  • Target: the object to receive the message
  • Action: a selector identifying the method to be invoked
99
Q

What is the superclass of UIControl?

A

UIView

100
Q

What is the Responder Chain?

A

The responder chain is a series of linked responder objects (i.e. those based on UIResponder).

It starts with the first responder and ends with the application object. If the first responder cannot handle an event, it forwards the event to the next responder in the responder chain.

101
Q

What’s the superclass of NSNumber?

A

NSValue

102
Q

How are Swift basic types (see below) implemented behind the scenes?

  • integers
  • floating-point numbers
  • Booleans
  • strings
  • arrays
  • dictionaries
A

As structs

103
Q

State the syntax for the following Swift type in its long form:

String?

A

Optional〈String〉

104
Q

What built-in class would you make a grid style view?

A

UICollectionView

105
Q

What should you be aware of if your app is running in the background state?

A

It could be suspended at any time

106
Q

How would you override the default behaviour of the active WiFi connection being closed after 30 minutes?

A

Set the Info.plist UIRequiresPersistentWifi key to YES.

107
Q

List the states than an app can be in, including when it is running and when it is not.

A
  1. Not running
  2. Active
  3. Inactive
  4. Background
  5. Suspended
108
Q

What is a bundle?

A

A bundle is a directory in the file system that groups related resources together in one place.

109
Q

What is contained in a typical app bundle?

A
  1. App executable file
  2. Information property list file
  3. App icons
  4. Launch images
  5. Storyboards/nibs
  6. Settings bundle
  7. Resources: images/media
  8. Localized content
110
Q

State the difference between the following Swift operators:

  • ==
  • ===
A

The double equals == performs an isEqual: type comparison wherease the triple equals === is an identity operator which you use to test whether two object references both refer to the same object instance

(I.e. == is like isEqual: etc in Objective C, and === is like == in Objective C)

111
Q

Can you subclass a Swift class from Objective C?

A

No

112
Q

Describe 3 categories of background execution

A
  1. Asking for more time (for short tasks)
  2. Handing off downloads to the system
  3. Specific background execution modes (as declared by the app) for specific tasks - e.g. playing audio, tracking location
113
Q

State the definition of Swift’s Array type

A
struct Array〈T〉 : MutableCollectionType, Sliceable {
 // Implementation
}
114
Q

Explain Content Hugging Priority

A

Higher priority means a view wants to hug its content and be its own size - it’s less likely to stretch when the space it’s in expands

(Note that horizontal and vertical are treated separately)

115
Q

Explain Content Compression Resistance Priority

A

Higher priority means a view has a greater resistance to compression - it’s less likely to get compressed when the space it’s in shrinks

(Note that horizontal and vertical are treated separately)

116
Q

Explain how Swift differs from Objective C with respect to creating mutable and immutable arrays and dictionaries

A

Objective C has different types that denote mutability (NSMutableArray and NSArray) whereas Swift uses var and let:

var mutableArray = [“This”, “is”, “mutable”]

let immutableArray = [“This”, “is”, “NOT”, “mutable”]

117
Q

State the 3 forms of closures in Swift

A
  1. Global functions - named closures that do not capture any values
  2. Nested functions - named closures that can capture values from their enclosing function
  3. Closure expressions - unnamed closures with lightweight syntax that can capture values from their surrounding context
118
Q

What is the first responder?

A

The first responder is a responder object that first receives various kinds of events in an application

This includes key events, motion events, and action messages, among others.

The first responder is typically the view in a window that an app deems best suited for handling an event.

In order to become first responder, the responder must return YES for canBecomeFirstResponder.

119
Q

What class would you use to work with regular expressions?

A

NSRegularExpression

120
Q

What class would you use to detect and extract dates, addresses, links, and more from strings?

A

NSDataDetector

(Note that it’s limited to its predefined types)

121
Q

Name a highly configurable class designed for scanning for and extracting subtrings and numeric values from loosely demarcated strings?

A

NSScanner

122
Q

Name 4 options for scanning and extracting values from strings

A
  1. NSString’s “componentsSeparatedBy” methods - basic but great if your string is in the appropriate form
  2. NSRegularExpression - powerful but can be cumberson
  3. NSDataDetector - perfect for detecting and extracting dates, addresses, links, etc. Limited to its predefined types
  4. NSScanner: Highly configurable and designed for scanning string and numeric values from loosely demarcated strings
123
Q

Name the superclass of NSDataDetector

A

NSRegularExpression

124
Q

What class would you use to do the following with a string?

  • Tokenize natural language strings into words
  • Determine their part-of-speech & stem
  • Extract names of people, places & organizations
  • Determine the languages & respective writing system
A

NSLinguisticTagger

125
Q

In Interface Builder, how does an outlet collection differ from a regular outlet?

A

An outlet collection allows one outlet (in code) to be associated with a collection of Interface Builder views/controls.

Instead of having properties in code representing every single control, you’d have a single array that represents the whole collection.

You then wire up each of the controls to the array in question.

This allows you to easily perform bulk operations on the controls (e.g. disable them all, etc).

126
Q

Name a workaround that would allow you to use an object whose class does not conform to NSCopying as an NSDictionary key

A

Wrap the object in an NSValue using NSValue’s valueWithNonretainedObject class/factory method.

The NSValue you get back will conform to NSCopying.

127
Q

What is Swift’s equivalent of Objective C’s id?

How does Swift ‘import’ id?

A

The AnyObject protocol.

Swift imports id as AnyObject.

128
Q

Discuss GCD’s dispatch_apply() function

A

dispatch_apply() acts like a for loop which executes iterations concurrently. It’s sychronous, so just like a normal for loop, it returns only when all of the work is done.

Example:

let q = dispatch\_get\_global\_queue(DISPATCH\_QUEUE\_PRIORITY\_LOW, 0)
dispatch\_apply(10, q) { print($0) }

Prints something like 0324517689

129
Q

State two options for concurrently processing an NSArray

A
  1. Using NSArray’s enumerateObjectsWithOptions:usingBlock: method and passing NSEnumerationConcurrent as an option
  2. Using GCD’s dispatch_apply(), which is more low level and ‘manual’ than the above
130
Q

How is NSArray bridged to Swift’s array?

A

[AnyObject]

131
Q

How is NSDictionary bridged to Swift’s dictionary?

A

[NSObject: AnyObject]

132
Q

Why does Swift need to represent Objective C’s NSObject protocol as NSObjectProtocol (and not just NSObject)?

A

In Swift, the namespace of protocols and classes is unified (i.e. you cannot have both a class and a protocol named NSObject).

In Objective C, you can have classes and protocols with the same name - as in the case of NSObject.

133
Q

What protocol should you conform to if your class handles encoding and decoding instances of itself in a manner that is robust against object substitution attacks?

What is the protocol does this protocol conform to?

A

NSSecureCoding

NSSecureCoding conforms to NSCoding

134
Q

State the replacement to UIWebView that was introduced with iOS 8.

What framework is it part of?

What advantages does it offer?

A

WKWebView (part of WebKit)

  • Performs better
  • Has the same JavaScript engine as Safari
  • Has streamlined communication between the app and webpage
135
Q

Name a simple way you can check for the OS verion that was introduced in iOS 8

A

Use the isOperatingSystemAtLeastVersion method of NSProcessInfo.

Swift example:

let minOS = NSOperatingSystemVersion(majorVersion: 8, minorVersion: 0, patchVersion: 0)
if NSProcessInfo().isOperatingSystemAtLeastVersion(minOS) {
 println("iOS 8.0.0+")
}
136
Q

Describe the difference between Swift and Objective C in terms of closures/blocks capturing variables in the surrounding scope

A

Swift: such variables are mutable, and changes will be reflected outside the closure.

Objective C: they are copied, and changes will not be reflected outside the closure. However you can use __block to achieve the Swift-like behaviour.

137
Q

List some of the things you can do using CFStringTransform

A
  1. Strip accents and diacritics​
  2. Transliterate between orthographies
  3. Encode/decode XML hex entities
  4. Determine the Unicode standard name for special characters (including Emjoji)
138
Q

What does CFStringTokenizer do?

A
  1. Allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way
  2. Supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds
  3. Provides language identification API
139
Q

State some ways of identifying the language used in a string

A
  1. Using NSLinguisticTagger to get an NSOrthography
  2. Using CFStringTokenizer’s language identification API
  3. Using textInputMode.primaryLanguage on a UIResponder (gets the language the user is currently typing rather than analyzing a string though)
140
Q

Describe how to setup a managed object context on a private queue, off the main queue/thread

A

[[NSManagedObjectContext alloc]
initWithConcurrencyType:NSPrivateQueueConcurrencyType];

  • The MOC will setup its own private dispatch queue
  • To execute code on the private queue you simply use performBlock: / performBlockAndWait:
    • (Many operations are not thread safe so you will need to perform them on the MOC’s queue)
141
Q

Describe an approach to concurrency with Core Data and Managed Object Contexts that allows flexibility in terms of potentially temporary/cancellable operations and also keeps heavy lifting out of the main thread.

A

We take advantage of parent/child MOCs as introduced in iOS 5:

  1. Master MOC connected to the persistent store with NSPrivateQueueConcurrencyType
  2. Main thread’s MOC (NSMainQueueConcurrencyType) as a child of master
  3. Intensive/background tasks done in worker MOCs which are setup as children of main MOC with the private concurrency type

[1] simply writes to disk and nothing else. [2] is your single source of truth and is used for all user interaction. [3] are for non-user data manipulation.

142
Q

Describe parent managed object contexts

A
  1. MOCs have a parent store from which they retrieve data and through which they commit changes
  2. Parent store can be a persistent store coordinator or another managed object context
  3. Root of a MOC’s ancestry must be a persistent store coordinator
  4. When you save changes in a context, the changes are only committed “one store up”
  5. Changes are not saved to the persistent store until the root context is saved
  6. A parent does not pull changes from children before it saves
143
Q

State 2 uses of parent/child managed object contexts

A
  1. Performing background operations on a second thread or queue
  2. Managing discardable edits, such as in an inspector window or view
144
Q

List the size classes used within an app’s UI

A

The following apply both horizontally and vertically:

  1. Compact
  2. Regular
  3. (Any)
145
Q

State the factors that determine the size class of a UI element

A
  1. The screen size of the device
  2. The orientation of the device
  3. The portion of the screen available to the view controller. For example, when a split view controller displays both the master and detail controllers, neither controller has access to the full screen
146
Q

With reference to an app’s UI, what is a size class?

A
  • A size class identifies a relative amount of display space for a UI element
  • There are two primary size classes:
    • Compact and Regular
  • Every screen or view defines a size class for both its horizontal and vertical dimensions - that is, its width and height
  • Hence we have four “abstract devices”:
    • Compact-Compact
    • Compact-Regular
    • Regular-Compact
    • Regular-Regular
147
Q

State the size classes of common devices and orientations

A

Regular width & regular height:

  • iPad portrait and landscape

Regular width & compact height:

  • iPhone 6 plus landscape

Compact width & regular height:

  • iPhone (all) portrait

Compact width & compact height:

  • iPhone (all except 6 plus) landsape
148
Q

Describe Swift’s NilLiteralConvertible

A
  • NilLiteralConvertible is a protocol
  • Conforming types can be initialized with nil (the literal)
  • Swift’s Optional type conforms to
    NilLiteralConvertible (as you might expect - but it’s an interesting point)
149
Q

State the definition of Swift’s Optional type

A
enum Optional〈T〉 : Reflectable, NilLiteralConvertible
{
 case None
 case Some(T)
 // Remaining implementation
}
150
Q

State the similarities and differences between weak and unowned references in Swift

A

Weak references and unowned references are both ways to resolve strong reference cycles when you work with properties of class type.

They enable one instance in a reference cycle to refer to the other instance without keeping a strong hold on it. They can then refer to each other without creating a strong reference cycle.

Use a weak reference whenever it is valid for that reference to become nil at some point during its lifetime.

Use an unowned reference when you know that the reference will never be nil once it has been set during initialization.

151
Q

In Swift, can you declare a weak reference as a constant value (i.e. using let)?

A

No. A weak reference cannot be declared as a constant.

Weak references must be declared as variables, to indicate that their value can change at runtime.

152
Q

Describe UIScreen

A
  • A UIScreen object defines the properties associated with a hardware-based display
  • iOS devices have a main screen and zero or more attached screens
  • Use this class to obtain screen objects for each display attached to the device
  • Each screen object defines the bounds rectangle for the associated display and other interesting properties such as its brightness.
153
Q

Give 4 examples of when you would use UIScreen

A
  1. When you want to determine the size of the display in physical pixels (not points)
  2. When you want to determine the brightness of a display
  3. When creating a UIWindow whose dimensions you want to match those of a screen
  4. When working with external displays
154
Q

How do you associate a UIWindow with a UIScreen?

A

Via UIWindow’s screen property

(By default, all windows are created on the primary device screen)

155
Q

Give two options for showing a UIWindow

A
  1. Use the hidden property inherited from the UIView superclass
  2. Call makeKeyAndVisible

In general you would use [1] if your window does not need to handle events, and [2] if it does.

156
Q

What is the superclass of UIScreen?

A

NSObject

157
Q

Describe UITraitEnvironment

A
  • UITraitEnvironment protocol
  • Provides access to iOS interface environment traits via the traitCollection property:
    • Horizontal and vertical size class
    • Display scale
    • User interface idiom
  • You can respond to changes in the interface environment (e.g. when an iPhone is rotated from portrait to landscape) via traitCollectionDidChange:
158
Q

Which classes conform to the UITraitEnvironment protocol?

A
  1. UIScreen
  2. UIWindow
  3. UIViewController
  4. UIPresentationController
  5. UIView
159
Q

What is the superclass of UIPresentationController?

A

NSObject

160
Q

What is the superclass of UIPopoverPresentationController?

A

UIPresentationController

161
Q

Describe UITraitCollection (as obtained via UITraitEnvironment)

A

​UITraitCollection provides (read only) access to the following properties:

  1. horizontalSizeClass
  2. verticalSizeClass
  3. displayScale (a float indicating whether retina or not)
  4. userInterfaceIdiom (i.e. iPhone or iPad)

You can also use it to compare trait collections.

162
Q

Discuss viewWillLayoutSubviews

A
  • viewWillLayoutSubviews is a method on UIViewController
  • When a view’€™s bounds change, the view adjusts the position of its subviews
    • This could happen as a result of change in orientation of the device
  • VCs can override this method to make changes before the view lays out its subviews
  • Default implementation does nothing
163
Q

What should you do if programmatically creating views in an autolayout environment?

A

Call setTranslatesAutoresizingMaskIntoConstraints: and pass it a value of NO.

Because the autoresizing mask naturally gives rise to constraints that fully specify a view’s position, any view that you wish to apply more flexible constraints to must be set to ignore its autoresizing mask using this method.

164
Q

Explain the difference between the following UIView methods:

  • layoutSubviews
  • setNeedsLayout
  • layoutIfNeeded
A
  • Override layoutSubviews to perform more precise layout of subviews
  • Call setNeedsLayout to invalidate the current layout of the receiver and trigger a subview layout update during the next update cycle
  • Call layoutIfNeeded to update the layout of subviews immediately
165
Q

Discuss the UIContentContainer protocol

A

The methods of the UIContentContainer protocol help you adapt the contents of your view controllers to size and trait changes.

All UIViewController and UIPresentationController objects provide default implementations for the methods of this protocol.

When creating your own custom view controller or presentation controller, you can override the default implementations to make adjustments to your content. For example, you might use these methods to adjust the size or position of any child view controllers.

166
Q

Explain the difference between the following UIView methods:

  • updateConstraints
  • setNeedsUpdateConstraints
  • updateConstraintsIfNeeded
A
  • Override updateConstraints to setup constraints
  • Call setNeedsUpdateConstraints to indicate that the view’s constraints need to be updated at some point in the future. The system will then call updateConstraints as part of its normal layout pass
  • Call updateConstraintsIfNeeded to update the constraints for the receiving view and its subviews in a more immediate fashion than setNeedsUpdateConstraints