Difference between shallow copy and deep copy?
Ans: Shallow copy is also known as address copy. In
this process you only copy address not actual data while in deep copy
you copy data.
Suppose there are two objects X and Y. X is pointing to a different
array while Y is pointing to different array. Now what I will do is
following to do shallow copy.
Char *X = {‘a’,’b’,’c’};
Char *B =
{‘r’,’s’,’t’};
Y = A;
Now B is pointing is at same location where A
pointer is pointing.Both X and Y in this case sharing same data. if
change is made both will get altered value of data.Advantage is that
coping process is very fast and is independent of size of array.
while in deep copy data is also copied. This process is slow but Both
A and B have their own copies and changes made to any copy, other will
copy will not be affected.
What is advantage of categories?
Ans: You can add method to existing class even to that
class whose source is not available to you. You can extend functionality
of a class without subclassing. You can split implementation in
multiple classes.
What is keyword atomic in Objective C?
Ans: When you place keyword atomic with a property, it means at one time only one thread can access it.
What are mutable and immutable types in Objective C?
Ans: Mutable means you can change its contents later
but when you mark any object immutable, it means once they are
initialized, their values cannot be changed. For example, NSArray,
NSString values cannot be changed after initialized.
Swap the two variable values without taking third variable?
Ans:-
int x=10;
int y=5;
x=x+y;
NSLog(@”x==> %d”,x);
y=x-y;
NSLog(@”Y Value==> %d”,y);
x=x-y;
NSLog(@”x Value==> %d”,x);
Thanks to Subrat for answering this question.