Introduction to Objective C Interview Questions and Answers
Objective C is a programming language which was developed in 1980. It can be said as a general purpose object-oriented programming language which adds Small talk style messaging to C programming. This is mainly famous as this was the main language which was used by Apple for building macOS and iOS operating systems. Later it was also selected as the main language which was to be used by NeXT. Below are a few questions which can be asked in an interview on objective C.
Now, if you are looking for a job which is related to Objective C then you need to prepare for the 2020 Objective C Interview Questions. It is true that every interview is different as per the different job profiles. Here, we have prepared the important Objective C Interview Questions and Answers which will help you get success in your interview.
In this article, we shall present 10 most important and frequently asked Objective C Interview questions. These questions are divided into two parts are as follows:
Part 1 – Objective C Interview Questions (Basic)
This first part covers basic Objective C Interview Questions and Answers
Q1. How do you manage memory in Objective C?
Memory allocation in Objective C is done dynamically. This means memory is allocated during the runtime of any program. It is being utilized and later it is freed when it is no longer required. This helps in using as little memory as possible. In this entire lifecycle of memory, the objects take up as much memory as they need and then free them when it is not required. For allocating memory in Objective C there are two ways:
- Manual Retain Release (MRR): In this type of memory management, memory is explicitly managed and all objects have kept a track of. It uses the reference counting model for keeping this track.
- Automatic Reference Counting (ARC): Here the system is capable of inserting an appropriate memory management method calls which are called the runtime.
The two main drawbacks with memory management are that once they are over freeing it causes to multiple system crashes and when it is not freeing then it leads to memory leaks, which results in the increase in memory footprint of the application.
Q2. What is declared properties in Objective C?
In Objective C, any property which is to be used it can be defined by declaring different instance variables by implementing getter and setter methods which help to enforce encapsulation. There are three aspects to properties. These include the declaration, implementation, and access. The properties can be declared in any class, category, and protocols in the declarative section. The syntax for this is as follows:
It also has attributes which are optional. Attributes can be as follows:
- Readonly: This property can only be read and not written into. This compiler does not have a setter accessor.
- Read-write: This property enables reading and writing both. The default mode is read-only.
- Assign: This is the simple assignment which can be used in the implementation of any setter.
- Retain: Retain is sent to the property once it is assigned.
- Copy: Like retain this operation is also performed once the property is assigned.
Let us move to the next Objective C Interview Questions
Q3. What are the characteristics of a category?
A category has the following characteristics: A category should be declared for any class even though there is no original source code available for implementation. The methods that are defined in a particular category are available for all instances to the class where it actually belongs. It can also be used in the subclasses of the original class like inheritance. There should not be any variation in a method which is appended by any category. Once it is implemented by the original class it can be used at runtime.
Q4. What is Retain count?
This is the basic Objective C Interview Question asked in an interview. The policy of ownership is implemented through reference counting. This retain count is taken after the retain method. Each object has a retain count and when an object is created its default retain count is 1. When this newly created object is sent as a retain message then the count is increased by 1. This count is decreased by 1 when an object is sent as the release message. It is also decreased when an object is sent an autorelease message at the end of the current autorelease pool. The object is released and deallocated when a retain count is decreased to 0.
Q5. When do we use NSArray and NSMutableArray?
NSArray is advised to be used when data in the array is not going to change. An example of this can be a company name which is going to seldom change and hence NS Array can be used so that no one manipulates it.
NSMutable Array: Unlike NS Array this array is used when data in an array tends to change. Here an example can be considered of a function which has values passing to the array as function and this function will append some elements to that array. At this time NSMutable array can be used.
Part 2 – Objective C Interview Questions (Advanced)
Let us now have a look at the advanced Interview Questions.
Q6. Is it possible to use ARC and Non-ARC code together in a project?
Yes, a project can use both ARC and Non-ARC codes. When a project chooses Non-ARC codes then –fobj-arc compiler flag is set. This ARC can be disabled for specific classes by using –fno-objc-arc.
This entire process can be done by Xcode → Project→ Build Phase→ Compile Sources→ Double Click on class and set the –fno-objc-arc.
Q7. What are the methods of using NSURL connection?
The methods that can be used in NSURL connection are the following connections:
- A connection which received the response
- A connection which receives data
- A connection which fails with error
- A Connection which did finish on loading
Let us move to the next Objective C Interview Questions
Q8. What is the protocol in Objective C?
A protocol is said to be a language feature which provides multiple inheritances in a language which has single inheritance. Objective C mainly supports two protocols:
Formal protocols are also known as compiler protocols and informal protocols also known as ad-hoc protocols.
Q9. How does message work in Objective C?
This is the most asked Objective C Interview Questions in an interview. Messaging is not bound to happen until a method is implemented in Objective C. A call messaging function objc_msgSend() is called when compiler transforms a message expression. This function connects to the receiver and the name of the method is mentioned in the message.
Q10. What is atomic and non-atomic in Objective C and which one is considered to be a default?
This method is used to specify the accessor methods which are not atomic. This ensures that the process which is being currently run is completed by the CPU before any other process accesses the variable. Non-atomic is for the variables which are non-atomic. These are faster but not thread safe.
This has been a guide to the list of Objective C Interview Questions and Answers. Here we have listed the most useful 10 interview sets of questions so that the jobseeker can crack the interview with ease. You may also look at the following articles to learn more –