Skip to content

Instantly share code, notes, and snippets.

@rcholic
Last active July 6, 2019 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcholic/397baee2dfd23ff3b46510ada68c4cac to your computer and use it in GitHub Desktop.
Save rcholic/397baee2dfd23ff3b46510ada68c4cac to your computer and use it in GitHub Desktop.

iOS Topic Questions

(from https://courses.codepath.com/courses/intro_to_ios/pages/ios_topic_questions)

Below you'll find questions that you should be able to answer after taking the iOS class. Some questions are commonly used in iOS interviews.

Views

CALayers are simply classes representing a rectangle on the screen with visual content. The neat thing about the CALayer class is that it contains a lot of properties that you can set on it to affect the visual appearance, such as: The size and position of the layer The layer’s background color The contents of the layer (an image, or something drawn with Core Graphics) Whether the corners of the layers should be rounded Settings for applying a drop shadow to the layer Applying a stroke around the edges of the layer

  • What is the difference between frame and bounds? The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

    The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

How are the typical values used for RGB different than the values used when creating a CGColor (using RGB parameters) and how do you account for this?

What view property must be true in order for gesture recognizers to work?

userInteractionEnabled

Give 1-2 examples of when it'd be a good idea to build a custom view.

Examples: Custom UIView that are used in multiple screens, **customized UIViews that the stock UIView libraries don't have, e.g. checkboxes, radio buttons, dropdown list, etc

Swift

Why isn’t ARC a garbage collector? What’s an autorelease pool?

Autorelease pool blocks provide a mechanism whereby you can relinquish ownership of an object, but avoid the possibility of it being deallocated immediately (such as when you return an object from a method). Typically, you don’t need to create your own autorelease pool blocks, but there are some situations in which either you must or it is beneficial to do so.

answer source:

The autoreleasepool pattern is used in Swift when returning autorelease objects (created by either your Objective-C code or using Cocoa classes). The autorelease pattern in Swift functions much like it does in Objective-C. For example, consider this Swift rendition of your method (instantiating NSImage/UIImage objects):

func useManyImages() {
    let filename = pathForResourceInBundle

    for _ in 0 ..< 5 {
        autoreleasepool {
            for _ in 0 ..< 1000 {
                let image = NSImage(contentsOfFile: filename)
            }
        }
    }
}

If you run this in Instruments, you'll see an allocations graph like the following: memory usage

But if you do it without the autorelease pool, you'll see that peak memory usage is higher: memory usage

Classes

Value Types: Struct

Why is casting a UIView to a UIImageView considered “down casting”

Because UIImageView is a subclass of UIView

View Controllers

What are the view controller lifecycle methods?

viewDidLoad(), viewDidAppear, viewWillAppear, viewWillDisappear,

What is the difference between viewDidLoad & viewDidAppear?

viewDidLoad is called exactly once, when the view controller is first loaded into memory. This is where you want to instantiate any instance variables and build any views that live for the entire lifecycle of this view controller. However, the view is usually not yet visible at this point.

viewDidAppear is called when the view is actually visible, and can be called multiple times during the lifecycle of a View Controller (for instance, when a Modal View Controller is dismissed and the view becomes visible again). This is where you want to perform any layout actions or do any drawing in the UI - for example, presenting a modal view controller. However, anything you do here should be repeatable. It's best not to retain things here, or else you'll get memory leaks if you don't release them when the view disappears.

When importing a view from another view controller programmatically, how do we call the view controller lifecycle methods of the view controller we are importing?

call view.layoutIfNeeded() to trigger the view controller lifecycle methods

What is a container view controller? When is it useful?

When should you add a new View Controller to your app?

Navigation

What method do we use to pass data to another view controller that we are navigating to? How do we pass data back when we are returning from another view controller? What use cases are best suited for show (push) navigation? What must we include any time we want to use show (push) navigation? What use cases are best suited for modal presentation? When would you want to use a custom view controller transition?

Optionals

What is a Swift optional and how is it notated? Why is force unwrapping optionals dangerous? What is optional chaining and when / why would you use this technique?

Storyboard connections

What is an outlet and when is it used? What is an Action and when is it used? Or What is target-action and when is it used? When creating Actions and Outlets, why is it advisable to drag from the document outline rather than from within the View Controller in the Storyboard? How do we associate a Swift File with a View Controller in the Storyboard?

Debugging

When you run into the exception ... this class is not key value coding-compliant for the key ..., what is the first thing to check? List at least 2 different reasons why you might encounter the error, “unexpectedly found nil while unwrapping an optional value ”, and explain how you might go about debugging this error? Scroll Views, Table Views Collection Views When using a UIScrollView, which method in UIScrollViewDelegate would you use to detect when UIScrollView has finished scrolling. How might you figure out if the user had scrolled to the bottom of a scroll view? What is cell recycling and why is it important? How does the Table View know which prototype cell to reuse? How do we access properties in our custom cell class from within the cellForRowAtIndexPath method? Where does all the logic associated with a particular cell go? Why do we avoid naming Image Views and Labels we create in a prototype cell, “imageView” and “label” respectively? What is a protocol? Where would you use protocols? What is UITableViewDataSource and when do you use it? What is UITableViewDelegate and when do you implement it? In which situations is it useful to use a CollectionView vs a TableView? If you have an image-intensive iPhone app and want to decrease the lag time when loading images from disk or going through the network, what are some potential approaches to solving this issue?

Cocoa Pods

What are Cocoa Pods? What's an example of when it can be helpful to use a pod? What are the advantages/disadvantages to including Pods in your gitignore file? App Architecture Describe the differing responsibilities of each component of the Model-View-Controller design pattern. Provide an example of MVC implementation. What's a singleton? Give an example of when you would want to use it. Or describe a use case where using a shared instance make the most sense? Auto Layout What is the difference between Auto Layout and Auto Resizing in iOS? What is the difference between content hugging priority & content compression resistance priority? What is intrinsic content size? How would you animate views with AutoLayout?

APIs

What does OAuth allow for? When would you want to use Parse? What data type to we typically get back from APIs? What method can we use to dig into nested dictionaries?

General Application

What does the NSUserDefaults class provide to you as the app developer? List & explain the different types of iOS Application States. What is the very first method that is called when an app launches and what file is it found in?

Closures

What is a closure?

source Closures are self contained chunks of code that can be passed around and used in your code. Closures can capture and store references to any constants or variables from the context in which they are defined. This is know as closing over those variables, hence the name closures. Closures are used intensively in the Cocoa frameworks – which are used to develop iOS or Mac applications.

How are closures helpful when passing data obtained from a network request?

The two most used cases are completion blocks and higher order functions in Swift.

Completion blocks: for example, when you have some time consuming task, you want to be notified when that task is finished. You can use closures for that, instead of a delegate (or many other things)

Higher order functions: you can use closures as input parameters for higher order functions, for example:

let array = [1, 2, 3]
let smallerThanTwo = array.filter { $0 < 2 }

Why do we need to use “self” inside the body of closures? use [weak self] to avoid the retain-cycle problem

Why does the UIView.animateWithDuration method utilize a closure?

Design

What are 1-2 examples of a good use of animation in some of the apps you use? What are the central frameworks that make up every iOS app? What do each do? When would you use AVFoundation instead of UIImagePickerController?

Choose an app that you use often and figure out all the different ways it leverages the device frameworks (i.e. camera, push notifications, maps, location, etc). What's the difference between using storyboards, xib's, and programmatic views in your app? What are the pros and cons of each one? When might you use Core Graphics?

Networking

What is the difference between NSURLConnection and NSURLSession? Now that there is NSURLSession, do we still need AFNetworking? Why or why not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment