What is Swift and what is Objective-C?
Objective-C is the primary programming language you use to write software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods.
Swift is a new programming language for iOS, OS X, watchOS, and tvOS apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift feels familiar to Objective-C developers and is friendly to new programmers.
What is the app lifecycle in iOS?
- Not running (The app has not been launched or was running but was terminated by the system.)
- Inactive (The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.)
- Active (The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.)
- Background (The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.)
- Suspended (The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so.
What type of tests can you write to test your iOS application and why tests are good practice?
There are two main types of automated tests for iOS: the unit tests and UI tests.
- Unit Tests are used to test that source code generates expected results. For example: ensuring that a function, when passed a specific parameter, generates some expected result.
- UI Tests test that a user interface behaves in an expected way. For example: a UI Test might programmatically tap on a button which should segue to a new screen, and then programmatically inspect whether the expected screen did load, and contains the expected content.
Automated tests can run on multiple devices and different SDKs. This means that automated tests can boost your testing productivity, save time, and lower development costs.
What are some ways of debugging in iOS?
- NSLog and print functions can be used for output into console.
- Breakpoints can also be used together with the Debug bar and Variables view as an alternative.
- Devs often use other tools such as Instruments and Crash Logs instead of the two above.
What is an optional and what problem do optionals solve?
An optional is used to let a variable of any type represent the lack of value. In Objective-C, the absence of value is available in reference types only, and it uses the nil special value. Value types, such as int or float, do not have such ability.
Swift extends the lack of value concept to both reference and value types with optionals. An optional variable can hold either a value or nil any time.
What is autorealease pool?
-autorelease is sent to an object, it is added to the inner-most autorelease pool. When the pool is drained, it simply sends
-release to all the objects in the pool.
Autorelease pools are a convenience that allows you to defer sending
-release until "later". That "later" can happen in several places, but the most common in Cocoa GUI apps is at the end of the current run loop cycle.
What is memory management handled on iOS?
iOS uses something called ARC which stands for Automatic Reference Counting. When an object is said to have a strong reference to it, ARC increases its retain count by 1. When the retain count of an object reaches 0, the object will typically be deallocated if there are no more strong references to it. Unlike garbage collection, ARC does not handle reference cycles automatically.
What is the difference between a class and an object?
In the simplest sense, a class is a blueprint for an object. It describes the properties and behaviors common to any particular type of object. An object, on the other hand, is an instance of a class.
Is it faster to iterate through an
NSArray or an
NSSet is faster to iterate through if the order of the items in the collection is not important. The reason is because
NSSet uses hash values in order to find items while
NSArray has to iterate through its entire contents to find a particular object.
What is the difference between implicit and explicit?
When referring to something as implicit or explicit, it is often referring to how an object is declared. In the two examples below:
var name: String = "onthecodepath" /* explicit */
var name = "onthecodepath" /* implicit */
What is the difference between weak and strong?
First, objects are strong by default.
Strong means that the reference count will be increased and the reference to it will be maintained through the life of the object.
Weak, means that we are pointing to an object but not increasing its reference count. It's often used when creating a parent child relationship. The parent has a strong reference to the child but the child only has a weak reference to the parent.
Common instances of weak references are delegate properties and subview/controls of a view controller's main view since those views are already strongly held by the main view.
What is the difference between category and extension in Objective-C?
A category and extension are similar in functionality where they can add additional instance and class methods to a class. However, an extension can only do so if the source code for the class being extended is available at compile time. This means that classes such as
NSString cannot be extended. Instead, a category would be used to add additional methods to the
In the first line above, the name variable is explicitly declared since the type of the variable follows the name of the variable. In the second line, the
String type is not explicitly declared. However, Swift is able to infer that name is of a
String type since the value that it is being set as is of a
#1 Product of the Day on ProductHunt 😼
Looking for world-class siOS Developers developer? Let us help you.Hire world-class iOS Developers
What is KVO?
KVO stands for Key-Value Observing. It allows a controller or class to observe when a property value changes.
Design Patterns, name and explain.
- Singleton Pattern
The Singleton design pattern ensures that only one instance exists for a given class and that there's a global access point to that instance. It usually uses lazy loading to create the single instance when it's needed the first time.
- Delegation pattern
The delegation pattern is a powerful pattern used in building iOS applications. The basic idea is that one object will act on another object's behalf or in coordination with another object. The delegating object typically keeps a reference to the other object (delegate) and sends a message to it at the appropriate time. It is important to note that they have a one to one relationship.
MVC stands for Model-View-Controller. It is a software architecture pattern for implementing user interfaces.
MVC consists of three layers: the model, the view, and the controller.
- The model layer is typically where the data resides (persistence, model objects, etc)
- The view layer is typically where all the UI interface lies. Things like displaying buttons and numbers belong in the view layer. The view layer does not know anything about the model layer and vice versa.
- The controller (view controller) is the layer that integrates the view layer and the model layer together.
MVVM stands for Model-View-ViewModel. It is a software architecture pattern for implementing user interfaces.
MVVM is an augmented version of MVC where the presentation logic is moved out of the controller and into the view model. The view model is responsible for handling most, if not all, of the view's display logic.
A common occurence in MVC is where you have a massive-view-controller (some joke this is what MVC stands for). In order to shrink the size of your view controller and make the logic and readibility of your code easier to follow along, the MVVM will be used.
What is protocol?
A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.
In addition to specifying requirements that conforming types must implement, you can extend a protocol to implement some of these requirements or to implement additional functionality that conforming types can take advantage of.
Which are the ways of achieving concurrency in iOS?
The three ways to achieve concurrency in iOS are:
- Dispatch queues
- Operation queues
What is GCD and how is it used?
GCD stands for Grand Central Dispatch. It offers the following benefits
- Improving your app's responsiveness by helping to defer computationally expensive tasks and run them in the background.
- Providing an easier concurrency model than locks and threads and helps to avoid concurrency bugs.
- Potentially optimize your code with higher performance primitives for common patterns such as singletons.
In other words, GCD provides and manages queues of tasks in the iOS app. This is one of the most commonly used API to manage concurrent code and execute operations asynchronously. Network calls are often performed on a background thread while things like UI updates are executed on the main thread.
Explain the difference between Serial vs Concurrent
Tasks executed serially are executed one at a time while tasks that are executed concurrently may be executed at the same time.
What is the difference between
viewDidAppear? Which should you use to load data from a remote server to display in the view?
viewDidLoad is only called when the view is loaded (after
loadView is called).
viewDidAppear, on the other hand, is called everytime the view appears on the device.
If the data is static for the most part, it can be loaded in
viewDidLoad and cached. But if the data is dynamic and likely to change often, it is preferrable to use
viewDidAppear. In both instances, data should be loaded asynchronously on a background thread to avoid blocking the UI.
What is the
reuseIdentifier indicates that cells for a
UICollectionView) can be reused.
UITableView maintains an internal cache of
UITableViewCell with the appropriate identifier and allows them to be reused when
dequeueForCellWithReuseIdentifier is called. As a result, this increases performance of
UITableView since a new view does not have to be created for a cell.
What considerations do you need when writing a
UITableViewController which shows images downloaded from a remote server?
- Only download the image when the cell is scrolled into view (when cellForRowAtIndexPath is called)
- Download the image asynchronously on a background thread so as not to block the UI so the user can keep scrolling
- When the image has downloaded for a cell, check if that cell is still in the view or whether it has been re-used by another piece of data. If the cell has been re-used, then the image should be discarded. Otherwise, it should be switched back to the main thread to change the image on the cell.
What is autolayout?
Auto Layout is used to dynamically calculate the size and position of views based on constraints.
Types of notification
Local notifications and remote notifications are ways to inform users when new data becomes available for an app, even when an app is not running in the foreground. The difference between local and remote notifications is straightforward:
With local notifications, the app configures the notification details locally and passes those details to the system, which then handles the delivery of the notification when the app is not in the foreground. Local notifications are supported on iOS, tvOS, and watchOS.
With remote notifications, one of your company's servers is used to push data to user devices via the Apple Push Notification service. Remote notifications are supported on iOS, tvOS, watchOS, and macOS.
iOS Data Storage options
NSUserDefaults- meant for storing small pieces of data such as settings, preferences, and individual values
Property List- Property lists are another great way to store our data. However like userDefaults it is not intended to save large amount of data.
SQLite- lightweight embedded relational database.
Keychain- for saving highly sensitive and secure data like passwords and secret codes.
- Saving Files- directly save all types of files to the file system.
CoreData- Apple's solution for persistence, allows applications to persist data of any form and retrieve it. Core Data isn't technically a database, although it usually stores its data in one (an SQLite database, to be precise).
Ways to distribute iOS App
Apple provides three ways to distribute your application based on which developer program you are a member of:
- App Store or iTunes Store: Publish an application to the iTunes Store.
- In House: Publish an application in house for company's employees. Members of the Apple Developer Enterprise program see this option instead of the App Store option.
- Ad Hoc: Publish an application as a package that can be distributed on a limited number of devices for testing.
#1 Product of the Day on ProductHunt 😼
Looking for world-class siOS Developers developer? Let us help you.Hire world-class iOS Developers