iOS General Flashcards
What states can a running UIApplication be in?
UIApplicationState: Active, Inactive, and Background
What classes would you use to encode and decode NSCoding compliant classes into a format that can be stored in a file?
NSKeyedArchiver and NSKeyedUnarchiver
What is the C-based API for concurrent programming?
Grand Central Dispatch
What is the object oriented API for concurrent programming?
NSOperation (and NSOperationQueue)
How many view controllers does a UISplitViewController manage?
Either one (if it is collapsed) or two
What is the main limitation when using Objective C categories?
A category cannot define new instance variables or add new storage to a class
Name a common cause of exc_bad_access
Trying to access an object that has been released (or not initialized)
Name a common way of tracking down the cause of exc_bad_access
Enable zombie objects within the Xcode scheme
What do you need to do in a project to use Swift from Objective C?
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)
What do you need to do in a project to use Objective C from Swift?
Create a ‘bridging header’ that imports the required code
Does a delegating object maintain a strong or weak reference to its delegate?
Weak
What is the Swift equivalent of Objective C categories?
Extensions
What is a workaround for categories not being able to add new instance variables to a class?
Use ‘Associated Objects’ via objc_[set,get]AssociatedObject
Which Foundation collection would you use for frequent containsObject: tests?
NSSet (it’ll be faster than NSArray)
What is required of classes that are to be used as dictionary keys?
Provide answers for both Objective C and Swift
Objective C: they must conform to NSCopying and implement copyWithZone:
Swift: they must conform to Hashable and implement var hashValue: Int { get }
What is a key requirement when implementing the isEqual: method?
If two objects are equal, they must have the same hash value
When would you use __block?
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
What is a retain cycle?
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)
Explain messages vs methods in Objective C
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
Name a way to add visual effects (such as blur or vibrancy) to a user interface
Using a UIVisualEffectView in conjunction with UIBlurEffect or UIVibrancyEffect
What’s the difference between UIModalPresentationFullScreen and UIModalPresentationOverFullScreen?
FullScreen removes the views beneath the presented view controller, whereas OverFullScreen does not (and hence they may still be visible in some form)
When would you use NSValue?
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)
When is a view controller’s preferredContentSize generally used?
When displaying the view controller’s content in a popover
How do you determine which view controller presented a view controller (if any)?
Use the UIViewController property presentingViewController
Should you call dismissViewControllerAnimated:completion: on the view controller you wish to dismiss, or the view controller that presented it?
The view controller that presented it
Name a built in way of evaluating a string containing an arithmetical expression such as “1 + 2 + 3”
NSExpression
Name a built in way of evaluating a string containing a logical expression such as “1 + 2 > 2”
NSPredicate
Name the logical drawing space used by native drawing technologies such as Quartz, UIKit, and Core Animation (i.e. not pixels!)
Points
State the difference and relationship between points and pixels
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.
State the logical resolution of an iPhone 4
320 x 480 (points)
State the logical resolution of an iPhone 5
320 x 568 (points)
State the logical resolution of an iPhone 6
375 x 667 (points)
State the logical resolution of an iPhone 6 plus
414 x 736 (points)
State the logical resolution of an iPad
1024 x 768 (points)
What is the superclass of UIView?
UIResponder
What is the superclass of UIApplication?
UIResponder
What is the superclass of UIResponder?
NSObject
What is the superclass of UIWindow?
UIView
What does it mean for a UIWindow to be a key window?
The key window is the one that is designated to receive keyboard and other non-touch related events
How many UIWindows can be the key window at any time?
Only one window at a time may be the key window
How do you get a UIApplication’s key window?
Via its keyWindow property
In general, how many UIWindows does an iOS app have?
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 do you get references to an application’s windows?
Via the windows property that UIApplication instances have.
How do you get the singleton UIApplication instace for your app?
UIApplication.sharedApplication()
What is a window’s root view controller? (As per the UIWindow rootViewController property)
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 do you get a window’s root view controller?
Via the rootViewController property on UIWindow instances
How do you get a view controller’s navigation controller (if there is one)?
Via the UIViewController navigationController property
What is the superclass of UIViewController?
UIResponder
How do you get a view controller’s split view controller (if there is one)?
Via the UIViewController.splitViewController property
How do you get a view controller’s tab bar controller (if there is one)?
Via the UIViewController tabBarController property
How would you determine the best size of a UIView considering all constraints it holds and those of its subviews?
Using systemLayoutSizeFittingSize() and passing it one of:
UILayoutFittingCompressedSize
UILayoutFittingExpandedSize
When considering a UIView’s subviews array, how does placement in the array affect the visible order on the screen (z order)?
The view at index 0 is the back-most view. The view at the highest index is the front-most view.
When considering the Interface Builder document outline, how does the vertical placement of views in the list relate to their z ordering?
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 do you get your application’s documents directory?
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.
Where should you store files on disk that you want to be persisted and backed up?
In the application’s documents directory
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)
NSSearchPathDirectory
Give a very rough outline of a strategy for having a popover on an adapting to a modal with navigation on iPhone
- Setup popover presentation segue without nav con
- In prepareForSegue set a delegate on the dest VC’s popoverPresentationController
- Use delegates’ presentationController:viewControllerForAdaptivePresentationStyle to return a nav con
How do you get a view controller’s popover presentation controller (if there is one)?
Using UIViewController’s popoverPresentationController property
In a navigation controller’s viewControllers array, at which index is the root view controller?
Index 0
In Core Data, what is the name of the resource that contains the definition of an application’s data structure / schema?
The Managed Object Model
In Core Data, what is the name of the resource that contains the applications data (for example, the SQLite database)?
The Persistent Store
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?
The Persistent Store Coordinator
Describe what a Managed Object Context is
- Single object space / scratchpad
- Manages a collection of managed objects
- (Internally consistent view of 1+ persistent stores)
- Fetching, creating
- Undo / redo
Can a managed object context have more than one managed object that represents a given record in a persistent store?
No - there can only be one
Describe what faulting means, with reference to Core Data
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
Describe uniquing, with reference to Core Data
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).