iOS Developers
iOS
Interview questions for beginners
1. What is the
difference between atomic and nonatomic?
atomic: It is the default behavior. If an object is
declared as atomic then it becomes thread-safe.
Thread-safe means, at a
time only one thread of a particular instance of that class can
have the control over
that object.
nonatomic: It is not thread-safe. You can use the
non-atomic property attribute to specify
that synthesized
accessors simply set or return a value directly, with no guarantees about
what happens if that
same value is accessed simultaneously from different threads. For this
reason, it’s faster to
access a non-atomic property than an atomic one.
2. What
is @Dynamic?
It tells the compiler
that getter and setter are not implemented by the class but by some other
class. May be super class or child class.
Example: Core Data
The Managed Object
classes have properties defined by using @dynamic.
3. What are Properties?
Properties enables us to
expose all the fields in your class so that you can control how values
are set or returned.
4. What is Delegate?
A delegate is an object
that acts on behalf of, or in coordination with, another object when that
object encounters an event in a program.
5. What is Protocol?
A protocol is a group of
related properties and methods that can be implemented by any class.
Creating Protocols:
StreetLegal.h
#import
<Foundation/Foundation.h>
@protocol StreetLegal
<NSObject>
- (void)signalStop;
- (void)signalLeftTurn;
- (void)signalRightTurn;
@end
Using Protocols:
Bicycle.h
#import
<Foundation/Foundation.h>
#import
"StreetLegal.h"
@interface Bicycle :
NSObject <StreetLegal>
- (void)startPedaling;
-
(void)removeFrontWheel;
- (void)lockToStructure:(id)theStructure;
@end
6. What are Strong and
Weak properties?
A strong
property is one where you increment the reference count of the object.
If object A
has a strong reference
to B, and no other object is referencing B, B has count 1 (A owns, or
needs to exist B). Now,
if B wants to have a reference to A, we would want to use a weak
reference. Weak
references don't increment the reference count of the object. So in
this
particular case, if A
has no other objects referencing it but B, A's count would be 0 given B's
weak reference.
7. Explain different App
States 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.
Active
- The app is running in
the foreground and is receiving events.
Background - The app is in the background and executing code.
Suspended
- The app is in the
background but is not executing code.
8. What are Web
Services and Explain?
Web Service is a
collection of protocols used for exchanging data between applications. Generally
in iOS we use web services like SOAP and REST API.
9. Explain SQLite
functions in iOS?
sqlite3_open(): This function creates and opens an empty
database with the specified
filename argument. If
the database already exists it will only open the database.
sqlite3_close(): This function should be used to close a
previously opened SQLite database
connection.
sqlite3_prepare_v2(): To execute an SQL statement it first needs to be
compiled into
byte-code and that is
exactly what this function is doing.
sqlite3_step( ): This function deletes a previously prepared SQL
statement from
memory.
sqlite3_finalize(): This function deletes a previously
prepared SQL statement from
memory.
sqlite3_exec(): Combines the functionality of
sqlite3_prepare_v2(), sqlite3_step() and
sqlite3_finalize() into
a single function call.
sqlite3_column_<type>(): This returns information about a single column
of the
current result row of a
query. Typical values for <type> are text and int.
10. What is Singleton
class in iOS?
The Singleton pattern
ensures that a class has only one instance and provides a global point of
access to that instance. In Singleton patterns two types are there.
1. Structural Patterns
2. Behavioral Patterns.
@interface SomeManager : NSObject
+ (id)singleton;
@end
@implementation SomeManager
+ (id)singleton {
static id sharedMyManager = nil;
@synchronized([MyObject class]){
if (sharedMyManager == nil) {
sharedMyManager = [[self alloc]
init];
}
}
return sharedMyManager;
}
@end
//using block
//using block
+ (id) singleton {
static SomeManager *sharedMyManager =
nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc]
init];
});
return sharedMyManager;
}
11. Explain MVC Design Pattern?
MVC means Model View Controller. It
is a design pattern that defines how to separate out logic when implementing
user interfaces
The Model represents
data in an application and can be implemented using any NSObject, including
data collections like NSArray and NSDictionary.
In iOS, Apple provides
UIView as a base class for all Views, UIViewController is provided to support
the Controller which can listen to events in a View and update the View when
data changes.
Some of the pitfalls
that people hit are bloated UIViewController and not separating out code into
classes beyond the MVC format.
12. What is
Notification?
Notifications is a process of broadcasting messages to
an interested parties. We use Notification to send messages in one to many ways.
13. Explain Difference
between Delegate and Notification?
Both are used for
sending values and messages to interested parties. A delegate is
for one-to-one communication and is a pattern promoted by Apple. In delegation
the class raising events will have a property for the delegate and will
typically expect it to implement some protocol. The delegating class can then
call the delegates protocol methods.
Notification allows a class to broadcast events across
the entire application to any interested parties. The broadcasting class
doesn't need to know anything about the listeners for this event, therefore
notification is very useful in helping to decouple components in an
application.
[NSNotificationCenter
defaultCenter]
postNotificationName:@"TestNotification"
object:self];
14. What are Blocks in
iOS?
Blocks are a way of
defining a single task or unit of behavior without having to write an entire
Objective-C class.You can create a blocks like
myBlock = ^{
NSLog(@"This is a
block");
}
15. What are Categories?
Categories enables us to add method to an existing class
without need to subclass it. You can also use a category to override the
implementation of existing class.
16.What is retain?
retain is required when the attribute is a
pointer to an object. The setter method will
increase retain count of
the object, so that it will occupy memory in auto release pool.
17. What is pool drain?
The drain keyword
is used to release the NSAutoreleasePool.
18. What is Autolayout?
AutoLayout is way of laying out UIViews using a set of
constraints that specify the location and size based relative to other views or
based on explicit values. AutoLayout makes it easier to design screens that
resize and layout out their components better based on the size and orientation
of a screen. Constraints include:
- setting the horizontal/vertical distance between 2
views
- setting the height/width to be a ratio relative to a
different view
- a width/height/spacing can be an explicit static value
19. What is
Multi-threading in iOS?
NSThread creates a low-level thread which can be started
by calling start method.
NSThread* myThread =
[[NSThread alloc] initWithTarget:self
selector:@selector(myThreadMainMethod:)
object:nil];
[myThread start];
NSOperationQueue allows a pool of threads to be created and
used to execute NSOperations in parallel. NSOperations can also be run on the
main thread by asking NSOperationQueue for the mainQueue.
NSOperationQueue*
myQueue = [[NSOperationQueue alloc] init];
[myQueue
addOperation:anOperation];
[myQueue
addOperationWithBlock:^{
/* Do
something. */
}];
GCD or Grand Central
Dispatch is a modern
feature of Objective-C that provides a rich set of methods and API's to use in
order to support common multi-threading tasks. GCD provides a way to queue
tasks for dispatch on either the main thread, a concurrent queue (tasks are run
in parallel) or a serial queue (tasks are run in FIFO order).
dispatch_queue_t myQueue
= dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(myQueue,
^{
printf("Do
some work here.\n");
});
20. What is Garbage
Collection?
Garbage Collection is a Memory Management feature. It manages
the allocation and release of the memory to your applications. When the garbage
collector performs a collection, it checks for objects in the managed heap that
are not executed by the applications.
21. What is Synchronous
and Asynchronous web request?
Synchronous web request means user will not get control if thread is
executing until task will complete. If you want to download data
from server continuously then you can use Synchronous web request. It is
Thread-Safe.
Asynchronous web request means user will get control automatically
even thread is executing. It is not Thread-Safe.
22. What is NSURLSession?
NSURLSession is the replacement for NSURLConnection from iOS
9. It is same as NSURLRequest and NSURLCache. NSURLSession has
three sub classes.
1. NSURLSessionDataTask
2.
NSURLSessionUploadTask and
3.
NSURLSessionDownloadTask
NSURL *url=[NSURL URLWithString:"http://example.com"];
NSURLRequest
*request=[NSURLRequest requestWithURL:url];
NSURLSession
*session=[NSURLSession sharedSession];
NSURLSessionDataTask
*task=[session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error)
{
//Do Something
}];
23. Difference between
SQLite and Core Data?
SQLite:
1. It is not a
relational database.
2. It is light-weighted
(It contains embedded SQL Engine)
3. It works as a part of
app.
Core Data:
1. Operates on objects
stored in memory.
2. Non-transactional,
single threaded, single user (unless you create an entire abstraction around
Core Data which provides these things).
24. Explain about Core
Data?
1. Core Data is
not a relational database. It is a framework that lets developers store or
retrieve data in database in an object oriented way.
2. With Core
Data, you can easily map the objects in your apps to the table records in
the database without knowing any SQL.
Core Data will work
mainly basis of three ways.
1. Managed
Object Model- It describes the schema represented by a collection of
objects(entities). In Xcode Managed Object Model is defined in a file with
extension .xcmodeld.
2. Persistent
Store Coordinator- By default SQLite is the persistent store in
iOS.Core Data allows developers to setup multiple stores containing different
entities. Persistent store coordinator is the party responsible to manage
different persistent object stores and save the objects to the stores. You will
not interact with persistent store coordinator directly when you are using Core
Data.
3. Managed Object Context- Whenever you need to fetch and save objects in persistent store, the context is the component responsible.
25. Explain about
Notifications?
Notifications is a process of broadcasting messages to an
interested parties. We use Notification to send messages in one to many way.
Notifications will work by using device tokens. There are two types of
notifications.
1. Local Notifications.
2. Push Notifications.
In Local Notifications
we will schedule time to broadcast notifications. We will place Local
Notifications code in AppDelegate file.
[[NSNotificationCentre
defaultCentre] postNotificationName:@"Testing"
object:self];
If you want to receive
notifications from server then you need to enable Push Notification feature.
Your app will receive notifications from server if any event occurs.
26. What is Automatic
Reference Counting (ARC)?
ARC is a compiler-level feature that
simplifies the process of managing the lifetimes of Objective-C objects.
Instead of you having to remember when to retain or release an object, ARC
evaluates the lifetime requirements of your objects and automatically inserts
the appropriate method calls at compile time.
27. What is posing in iOS?
Objective-C permits a
class to entirely replace another class within an application.
The replacing class is said to “pose as” the target class. All messages sent to
the target class are then instead received by the posing class.
28. InApp purchase product type
1. Consumable products must be purchased each time the
user needs that item. For example, one-time services are commonly implemented
as consumable products.
2. Non-consumable products are purchased only once by
a particular user. Once a non-consumable product is purchased, it is provided
to all devices associated with that user’s iTunes account. Store Kit provides
built-in support to restore non-consumable products on multiple devices.
3. Auto-renewable subscriptions are delivered to all
of a user’s devices in the same way as non-consumable products. However,
auto-renewable subscriptions differ in other ways. When you create an
auto-renewable subscription in iTunes Connect, you choose the duration of the
subscription. The App Store automatically renews the subscription each time its
term expires. If the user chooses to not allow the subscription to be renewed,
the user’s access to the subscription is revoked after the subscription
expires. Your application is responsible for validating whether a subscription
is currently active and can also receive an updated receipt for the most recent
transaction.
4. Free subscriptions are a way for you to put
free subscription content in Newsstand. Once a user signs up for a free
subscription, the content is available on all devices associated with the
user’s Apple ID. Free subscriptions do not expire and can only be offered in Newsstand-enabled
apps.
29. What is KVC and KVO?
Give an example of using KVC to set a value.
KVC stands for
Key-Value Coding. It's a mechanism by which an object's properties can be
accessed using strings at runtime rather than having to statically know the property
names at development time.
KVO stands for Key-Value Observing and
allows a controller or class to observe changes to a property value.
Let's say there is a
property name on a class:
@property (nonatomic, copy) NSString *name;
We can access it using
KVC:
NSString *n = [object valueForKey:@"name"];
And we can modify its
value by sending it the message:
[object setValue:@"Mary" forKey:@"name"];
30. What is the Responder Chain?
When an event happens in a view, for example a
touch event, the view will fire the
event to a chain of UIResponder objects
associated with the UIView. The first
UIResponder is the UIView itself, if it does not
handle the event then it
continues up the chain to until UIResponder
handles the event. The chain will
include UIViewControllers, parent UIViews and
their associated
UIViewControllers, if none of those handle the
event then the UIWindow is asked
if it can handle it and finally if that doesn't
handle the event then the
UIApplicationDelegate is asked.
31. Enlist the methods to achieve Concurrency in
iOS.
The following listed are the methods to achieve
concurrency functionality in iOS:
1. Threads
2. Dispatch Queues
3. Operation Queues
32. Differentiate between Release and Pool
Drain.
The release keyword is used to free a memory
location in the system which is not being
utilized. The drain keyword is used to release
the NSAutoreleasePool.
33. What is a Collection?
A Collection is a Foundation Framework Class
that is used to Manage and Store the group of
Objects. The primary role of a Collection is to
store Objects in the form of
either a Set, a Dictionary or an Array.
34. Explain the significance of AutoRelease.
When you send an Object AutoReleasemessage, it
gets added to the Local AutoRelease Pool.
When the AutoRelease Pool gets destroyed, the
Object will receive a Release message. The
Garbage Collection functionality will destroy
the object if it has the RetainCount as Zero.
35. What is the First Responder and Responder
Chain?
A Responder Chain is a hierarchy of Objects that
can respond to the events received. The
first object in the ResponderChain is called the
First Responder.
For Android Interview questions and Answers
For Android Interview questions and Answers
Awesome blog you given very well defined stuff to us. Thanks for sharing.We do provide iOS app development course check out here for our demo and best offers with us. Thanks for sharing.
ReplyDeletehttp://tekclasses.com/course/ios-app-development-course/