iphone Interview Questions part-9

91-What is accessor methods?

Accessor methods are methods belonging to a class that allow to get and set the values of instance valuables contained within the class.

92-What is synthesized accessor methods?

Objective-c provides a mechanism that automates the creation of accessor methods that are called synthesized accessor methods that are implemented through use of the @property and @synthesized.

93-How to access the encapsulated data in objective-c?

(a)Data encapsulation encourages the use of methods to +get and set the values of instance variables in a class.

(b)But the developer to want to directly access an instance variable without having to go through an accessor method.

(c) In objective-c syntax for an instance variable is as follow [class instance variable name]

94-What is dot notation?

Dot notation features introduced into version 2.0 of objective-c. Dot notation involves accessing an instance variable by specifying a class “instance” followed by a “dot” followed in turn by the name of instance variable or property to be accessed.

95-Difference between shallow copy and deep copy?

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 A and B. A is pointing to a different array while B is pointing to different array. Now what I will do is following to do shallow copy.Char *A = {‘a’,’b’,’c’};Char *B = {‘x’,’y’,’z’};B = A;Now B is pointing is at same location where A pointer is pointing.Both A and B 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.

96-Difference between categories and extensions?

Class extensions are similar to categories. The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation, whereas with a category you have a separate @implementation block. So you should pretty much only use an extension at the top of your main .m file (the only place you should care about ivars, incidentally) — it’s meant to be just that, an extension.

97-What are KVO and KVC?

KVC: Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings. In this way your class acts like a dictionary and your property name for example “age” becomes key and value that property holds becomes value for that key. For example, you have employee class with name property.

You access property like

NSString age = emp.age;

setting property value.

emp.age = @”20″;

Now how KVC works is like this

[emp valueForKey:@”age”];

[emp setValue:@”25″ forKey:@”age”];

KVO : The mechanism through which objects are notified when there is change in any of property is called KVO.

For example, person object is interested in getting notification when accountBalance property is changed in BankAccount object.To achieve this, Person Object must register as an observer of the BankAccount’s accountBalance property by sending an addObserver:forKeyPath:options:context: message.

98-Can we use two tableview controllers on one view controller?

Yes, we can use two tableviews on the same view controllers and you can differentiate between two by assigning them tags…or you can also check them by comparing their memory addresses.

99-Swap the two variable values without taking third variable?

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);

100-What is push notification?

Imagine, you are looking for a job. You go to software company daily and ask sir “is there any job for me” and they keep on saying no. Your time and money is wasted on each trip.(Pull Request mechanism)

So, one day owner says, if there is any suitable job for you, I will let you know. In this mechanism, your time and money is not wasted. (Push Mechanism)

How it works?

This service is provided by Apple in which rather than pinging server after specific interval for data which is also called pull mechanism, server will send notification to your device that there is new piece of information for you. Request is initiated by server not the device or client.

Flow of push notification

Your web server sends message (device token + payload) to Apple push notification service (APNS) , then APNS routes this message to device whose device token specified in notification.


Discover more from mycodetips

Subscribe to get the latest posts sent to your email.

Discover more from mycodetips

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top