IOS Interview Questions and Answers
Here you can find IOS Interview Questions and Answers.
Why IOS Interview Questions and Answers Required?
In this IOS Interview Questions and Answers section you can learn and practice IOS Interview Questions and Answers to improve your skills in order to face technical
inerview by IT companies. By Practicing these interview questions, you can easily crack any IOS interview.
Where can I get IOS Interview Questions and Answers?
AllIndiaExams provides you lots IOS Interview Questions and Answers with proper explanation. Fully solved examples with detailed answer description. All students,
freshers can download IOS Interview Questions and Answers as PDF files and eBooks.
How to solve these IOS Interview Questions and Answers?
You no need to worry, we have given lots of IOS Interview Questions and Answers and also we have provided lots of FAQ's to quickly answer the questions in the IOS
technical interview.
IOS Interview Questions and Answers
What is init ?
init is an instance method, used to initialize a particular object
IOS Interview Questions and Answers
What is new ?
NSObject implements a class method "new" which simply calls "alloc" and "init"
IOS Interview Questions and Answers
What is the difference between init and new ?
new doesn't support custom initializers (like init With String)
alloc-init is more explicit than new
IOS Interview Questions and Answers
What is retain ?
it is retained, old value is released and it is assigned -retain specifies the new value should be sent -retain on assignment and the old value sent -release -retain is the same as
strong.apple says if you write retain it will auto converted/work like strong only. -methods like "alloc" include an implicit "retain"
IOS Interview Questions and Answers
What is ARC?
Automatic Reference Counting, or ARC was introduced in iOS 5,is a feature of the new LLVM 3.0 compiler and it completely does away with the manual memory
management.you no longer call retain, release and autorelease.With Automatic Reference Counting enabled, the compiler will automatically insert retain, release and autorelease in
the correct places in your program ARC is not a runtime feature (except for one small part, the weak pointer system), nor is it *garbage collection* that you may know from other
languages.All that ARC does is insert retains and releases into your code when it compiles it.
OR
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.
IOS Interview Questions and Answers
What is atomic?
Atomic means only one thread access the variable(static type).
Atomic is thread safe.
But it is slow in performance.
Atomic is default behaviour.
Atomic accessors in a non garbage collected environment (i.e. when using retain/release/autorelease) will use a lock to ensure that another thread doesn't interfere with the correct
setting/getting of the value. -it is not actually a keyword.
Example :
@property (retain) NSString *name;
@synthesize name;
IOS Interview Questions and Answers
What is nonatomic?
Nonatomic means multiple thread access the variable(dynamic type).
Nonatomic is thread unsafe.
But it is fast in performance.
Nonatomic is NOT default behavior,we need to add nonatomic keyword in property attribute.
It may result in unexpected behavior, when two different process (threads) access the same variable at the same time.
IOS Interview Questions and Answers
What is strong (iOS4 = retain ) ?
It says "keep this in the heap until I don't point to it anymore"
In other words " I'am the owner, you cannot dealloc this before aim fine with that same as retain"
You use strong only if you need to retain the object. -By default all instance variables and local variables are strong pointers.
We generally use strong for UIViewControllers (UI item's parents)
Strong is used with ARC and it basically helps you , by not having to worry about the retain count of an object.
ARC automatically releases it for you when you are done with it.
Using the keyword strong means that you own the object.
Example:
@property (strong, nonatomic) ViewController *viewController;
@synthesize viewController;
IOS Interview Questions and Answers
What is weak (iOS4 = unsafe_unretained )?
It says "keep this as long as someone else points to it strongly" -the same thing as assign, no retain or release.
A "weak" reference is a reference that you do not retain.
We generally use weak for IBOutlets (UIViewController's Childs).
This works because the child object only needs to exist as long as the parent object does.
A weak reference is a reference that does not protect the referenced object from collection by a garbage collector.
Weak is essentially assign, a unretained property.
Except the when the object is deallocated the weak pointer is automatically set to nil
Example :
@property (weak, nonatomic) IBOutlet UIButton *myButton;
@synthesize myButton;
Explain:
Imagine our object is a dog, and that the dog wants to run away (be deallocated). Strong pointers are like a leash on the dog. As long as you have the leash attached to the dog,
the dog will not run away. If five people attach their leash to one dog, (five strong pointers to one object), then the dog will not run away until all five leashes are detached. Weak
pointers, on the other hand, are like little kids pointing at the dog and saying "Look! A dog!" As long as the dog is still on the leash, the little kids can still see the dog, and they'll
still point to it. As soon as all the leashes are detached, though, the dog runs away no matter how many little kids are pointing to it. As soon as the last strong pointer (leash) no
longer points to an object, the object will be deallocated, and all weak pointers will be zeroed out. When we use weak? The only time you would want to use weak, is if you
wanted to avoid retain cycles (e.g. the parent retains the child and the child retains the parent so neither is ever released).
IOS Interview Questions and Answers
What is retain = strong ?
It is retained, old value is released and it is assigned
retain specifies the new value should be sent
retain on assignment and the old value sent
release -retain is the same as strong.
apple says if you write retain it will auto converted/work like strong only.
methods like "alloc" include an implicit "retain"
Example:
@property (nonatomic, retain) NSString *name;
@synthesize name;