iphone interview questions (1)
TRANSCRIPT
-
7/28/2019 iPhone Interview Questions (1)
1/25
IOS INTERVIEW QUESTIONS WITH ANSWERS
Q1.What is property?
Ans:Properties are used to access the instance variables from outside of class.
Q2. What is synthesized?
Ans:After you declare the property in objective-c . we have to tell the compiler instantly by
using synthesize directive. Actually this tells to compiler to generate a getter&setter message.
3Q: How many bytes we can send to apple push notification server.
A:256bytes.
Q4. What is retaining?
Ans:It is reference count of the object
Q5. What is webservice?
Ans:Main purpose is to expose the data in form of xml format ,by using this we can getting
the data from server.
Q6. What is parsing?
Ans:To access the data in the xml element is called parsing.
Q7.Which class we can use for passing of xml in iphone?
Ans:By NSXML Parser.
Q8.Which type of parse we have use in iphone?
Ans:SAX parser.
Q9.Which class are used to establish connection b/w application to webserver?
Ans:(a)NSURL
(b)NSURL REQUEST
(c)NSURL CONNECTION.
Q10.What is difference between DOM&SAX?
Ans:(a)Dom is a documents based parser. When we will work with these parser all the data of xml
is stored in RAM.In this parser memory consumption is more.
(b)SAX is a event driven parser.When we will work with these parser,take only reference from
xml file and generate the one event for every element.
Q11.After parsing if you want to get your data in view which delegation methods are did
-
7/28/2019 iPhone Interview Questions (1)
2/25
you use?
Ans:(a)did start element (b)did end elemen (c)found character.
Q12.How many methods are used in NSURLConnection?
Ans:I have 4 types methods(a)Connection did receive Response
(b)Connection did recevice Datat
(c)Connection fail with error
(d)Connection did finish loading.
Q13.Tell me about json-parser?
Ans:JSON Means Java script object notation.
It is a one type of parser (or)test-based and hightweight parser.
Q14.By default application which things contain?
Ans:In ipone applications by default having 3 things
1.mainIt is entry point of application.
2.AppdelegateIt is perform the basic application & functionality.
3.WindowIt is provide uiinterface.
Q15.What is uiviewcontroller?
Ans: uiview controller is base class for all the controller.
Q16. What is the navigation controller?
Ans: Navigation controller contains the stack of controllers every navigation controller
must be having root view controller by default these controllers contain 2 method
(a) push view (b) pop view
By default navigation controller contain table view.
Q17. What is tab bar controller?
Ans: Tab bar is used to common way to display the data on iphone.
Q18. What is the table view controller?
Ans: Table view controller contains the number of rows and columns visible in the
application and makes a cell editable or not as a response to key press
Q19. Which protocols are did used in table view?
Ans: Table view contain 2 delegate protocols
(a). Ui table view data source
(b). Ui table view delegate.
In ui view table view data source contain these methods(a). No of sections.
(b). No of rows in sections.
-
7/28/2019 iPhone Interview Questions (1)
3/25
(c). Cell for row index path row.
In ui table view delegate contain these methods
(a). Did select row at index path row
Q20. By default table view which controller contain?
Ans: Detail view controller that is present is ui table view delegate
Q21. What is the split view controller?
Ans: This control is used for ipad application and it contain proper controllers by default split view
controller contain root view controller and detail view controller.
Q22. What are data base are used in iphone?
Ans: (a). Sql lite (b). Plist c). Xml (d). core data
(
Q23. Tell me about the MVC architecture?
Ans: M-model, V-view, C-controller
Main advantage of MVC architecture is to provide reusability and security
by separating the layer by using MVC architecture.
Model: it is a class model is interact with database.
Controller: controller is used for by getting the data from model and controls the views.
View display the information in views.
Q24. What are frame works are used in iphone?
Ans: (a). Ui kit framework
(b). Map kit framework
(c). ADI kit framework
(d). Core data framework
(e).core foundation framework
Q25. What is the instance methods?
Ans: Instance methods are essentially code routines that perform tasks so instancesof clases we create methods to get and set the instance variables and to display
the current values of these variables.
Declaration of instance method :
- (void)click me: (id)sender;
Void is return type which does not giving any thing here.
Click me is method name.
Id is data type which returns any type of object.
Q26. What is the class method?
Ans: Class methods work at the class level and are common to all instance of a
class these methods are specific to the class overall as opposed to working
-
7/28/2019 iPhone Interview Questions (1)
4/25
on different instance data encapsulated in each class instance.
@interface class name :ns object
{
}
+(class name *)new alloc:
-(int)total open
Q27. What is data encapsulation?
Ans: Data is contained with in objects and is not accessible by any other than
via methods defined on the class is called data encapsulation.
Q28. What is accessor methods?
Ans: Accessor methods are methods belonging to a class that allow to get and set
the values of instance valuables contained with in the class.
Q29. What is synthesized accessor methods?
Ans: 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.
Q30. How to access the encapsulated data in objective-c?
Ans:(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 with out having to go through
an accessor method.
(c) In objective-c syntax for an instance variable is as follow [class instance variable name]
Q31. What is dot notation?
Ans: 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.
Q32. What is single inheritance in objective-c?
Ans: Objective-c subclass can only be derived from a single direct parent class this s concept is
called as single inheritance.
Q33. Ns object is parent class or derived class?
Ans: Ns object is parent class and contains a number of instance variables and instance methods.
Q34. How to call function in objective-c
Ans: [account display account info]Account-> object namey Subclassing the UIView class.
Display account info-> method name
-
7/28/2019 iPhone Interview Questions (1)
5/25
35Q: What is App Bundle?
A:When you build your iOS app, Xcode packages it as a bundle. A bundle is a directory in the file
system that groups related resources together in one place. An iOS app bundle contains the app
executable file and supporting resource files such as app icons, image files, and localized content.
From your code, access your apps resource files using anNSBundle object:
1. Use the mainBundle method of NSBundle to obtain your apps main bundle object.2. Use the methods of the bundle object to obtain the location of the desired resource file.
3. Open (or access) the file and use it.
The pathForResource:ofType: method is one of several NSBundle methods that you can use to
retrieve the location of resource files in your bundle. The following example shows how to locate
an image file called sun.png and create an image object. The first line gets the location of the file in
the bundle. The second line creates the UIImage object using the data in the file at that location.
36Q: Whats fast enumeration?
A:Fast enumeration is a language feature that allows you to enumerate over the contents of a
collection. (Your code will also run faster because the internal implementation reducesmessage send
overhead and increases pipelining potential.)
37Q: Whats a struct?A:A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit.
Like an object, but built into C. *
38Q: Whats the difference between NSArray and NSMutableArray?
A:NSArray s contents can not be modified once it s been created whereas a NSMutableArray can be
modified as needed, i.e items can be added/removed from it.
39 Q: Explain retain counts.
A:Retain counts are the way in which memory is managed in Objective-C. When you create an
object, it has a retain count of 1. When you send an object a retain message, its retain count is
incremented by 1. When you send an object a release message, its retain count is decremented by 1.
When you send an object a autorelease message, its retain count is decremented by 1 at some stage
in the future. If an object s retain count is reduced to 0, it is deallocated.40Q: Whats the difference between frame and bounds?
A:The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative
to the superview it is contained within. The bounds of a view is the rectangle, expressed as a
location (x,y) and size (width,height) relative to its own coordinate system (0,0).
41 Q: Is a delegate retained?
A:No, the delegate is never retained! Ever!
42Q: Outline the class hierarchy for a UIButton until NSObject.
A:UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from
UIResponder, UIResponder inherits from the root class NSObject
43Q: What is dynamic?A:You use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied
by a property either by providing method implementations directly or at runtime using other
mechanisms such as dynamic loading of code or dynamic method resolution. It suppresses the
warnings that the compiler would otherwise generate if it cant find suitable implementations. You
should use it only if you know that the methods will be available at runtime
iOS Questions for Intermediate level
44Q:If I call performSelector:withObject:afterDelay: is the object retained?
A:Yes, the object is retained. It creates a timer that calls a selector on the current threads run loop. It
may not be 100% precise time-wise as it attempts to dequeue the message fromthe run loop and
perform the selector.
45Q: Can you explain what happens when you call autorelease on an object?A:When you send an object a autorelease message, its retain count is decremented by 1 at some
stage in the future. The object is added to an autorelease pool on the current thread. The main thread
http://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/cl/NSBundlehttp://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/clm/NSBundle/mainBundlehttp://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/pathForResource:ofType:http://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/pathForResource:ofType:http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/cl/UIImagehttp://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/clm/NSBundle/mainBundlehttp://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/pathForResource:ofType:http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/cl/UIImagehttp://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/cl/NSBundle -
7/28/2019 iPhone Interview Questions (1)
6/25
loop creates an autorelease pool at the beginning of the function, and release it at the end. This
establishes a pool for the lifetime of the task. However, this also means that any autoreleased
objects created during the lifetime of the task are not disposed of until the task completes. This may
lead to the task s memory footprint increasing unnecessarily. You can also consider creating pools
with a narrower scope or use NSOperationQueue with it s own autorelease pool. (Also important
You only release or autorelease objects you own.)
46 Q: Whats the NSCoder class used for?A:NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and
Unarchiving objects. NSCoder objects are usually used in a method that is being implemented so
that the class conforms to the protocol. (which has something like encodeObject and decodeObject
methods in them).
47 Q: Whats an NSOperationQueue and how/would you use it?
A:The NSOperationQueue class regulates the execution of a set of NSOperation objects. An
operation queue is generally used to perform some asynchronous operations on a background thread
so as not to block the main thread.
48Q: Explain the correct way to manage Outlets memory
A:Create them as properties in the header that are retained. In the viewDidUnload set the outlets to
nil(i.e self.outlet = nil). Finally in dealloc make sure to release the outlet.iOS Questions for Expert level
49Q: Is the delegate for a CAAnimation retained?
A:Yes it is!! This is one of the rare exceptions to memory management rules.
50Q: What happens when the following code executes?
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
A:It will crash because it s added twice to the autorelease pool and when it it dequeued the
autorelease pool calls release more than once.
51 Q: Explain the difference between NSOperationQueue concurrent and non-concurrent.
A:In the context of an NSOperation object, which runs in an NSOperationQueue, the terms
concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads.
Instead, a non-concurrent operation is one that executes using the environment that is provided for it
while a concurrent operation is responsible for setting up its own execution environment.
-
7/28/2019 iPhone Interview Questions (1)
7/25
InterView Questions 2
* What is iPhone OS?
Ans. iPhone OS runs on iPhone and iPod touch devices. Hardware devices are managed by iPhone
OS and provides the technologies needed for implementing native applications on the phone. The
OS ships with several system applications such as Mail, Safari, Phone, which provide standardservices to the user.
* What is iPhone sdk?
Ans. iPhone SDK is available with tools and interfaces needed for developing, installing and
running custom native applications. Native applications are built using the iPhone OSs system
frameworks and Objective-C language and run directly on iPhone OS. Native applications are
installed physically on a device and can run in presence or absence of network connection.
* What is iPhone Architecture?
Ans. It is similar to MacOS X architecture. It acts as an intermediary between the iPhone and iPod
hardware an the appearing applications on the screen. The user created applications never interactdirectly with the appropriate drivers, which protects the user applications from changes to the
hardware.
* What is MVC ? MVC Architecture of iPhone App.
Ans. Here are the reasons why we should use the MVC (Model View Controller)design pattern.
1. They are resuable : When the problems occurs, there is no need to invent a new solution, we
just have to follow the pattern and adopt it as necessary.
2. They are expressive: By using the MVC design pattern our application becomes more
expressive.
1). Model: The model object knows about all the data that need to be displayed. It is model who is
aware about all the operations that can be applied to transform that object. It only represents the
data of an application. The model represents enterprise data and the business rules that govern
access to and updates of this data. Model is not aware about the presentation data and how that data
will be displayed to the browser.
2).View: The view represents the presentation of the application. The view object refers to the
model. It uses the query methods of the model to obtain the contents and renders it. The view is not
dependent on the application logic. It remains same if there is any modification in the business
logic. In other words, we can say that it is the responsibility of the of the view's to maintain the
consistency in its presentation when the model changes.
3).Controller: Whenever the user sends a request for something then it always go through the
controller. The controller is responsible for intercepting the requests from view and passes it to themodel for the appropriate action. After the action has been taken on the data, the controller is
responsible for directing the appropriate view to the user. In GUIs, the views and the controllers
often work very closely together.
* What are the ways to store data localy on device ?
Ans. We store data localy in device through:
1. Plist.
2. NSUserDefaults.
3. SQLite.
4. CoreData.
* Difference between COCOA,COCOA touch and objective C ?
Ans. Objective C is a dynamic programming language - a bit like C++ and a bit like Java.
-
7/28/2019 iPhone Interview Questions (1)
8/25
Cocoa is the application framework for Mac OS X. Cocoa Touch is the application framework for
iPhone and iPod Touch - very similar to Cocoa. Cocoa is commonly referred to as the combination
of the Foundation and AppKit frameworks, while Cocoa Touch is the combination of the
Foundation and UIKit frameworks. Cocoa and Cocoa Touch sit on top of other collections of
frameworks to create the API stacks. The other layers are Media, Core Services and Core OS. The
main difference between Cocoa and Cocoa touch is that the UI classes and APIs aren't the same as
Mac OS X, so instead of NSTextField, you have UITextField. Many of the classes share the samefunctionality and can be ported quite easily by simply changing the class name, though most will
require some more changes, but usually nothing too heavy. There are also some differences between
the Foundation frameworks in Cocoa and Cocoa Touch, most commonly missing classes, eg, Cocoa
has NSHost and Cocoa Touch doesn't.
* 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 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 willget 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? What is difference between implementing a category and
inheritance?
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. While in Inheritance you subclass from parent class and extend its functionality.
* Flow of push notification?
Ans. 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.
* What is polymorphism?
Ans. This is very famous question and every interviewer asks this. Few people say polymorphism
means multiple forms and they start giving example of draw function which is right to some extent
but interviewer is looking for more detailed answer. Ability of base class pointer to call function
from derived class at runtime is called polymorphism. For example, there is super class human and
there are two subclasses software engineer and hardware engineer. Now super class human can hold
reference to any of subclass because software engineer is kind of human. Suppose there is speakfunction in super class and every subclass has also speak function. So at runtime, super class
reference is pointing to whatever subclass, speak function will be called of that class. I hope I am
able to make you understand.
* When to use NSMutableArray and when to use NSArray?
Ans. Normally we use mutable version of array where data in the array will change. For example,
you are passing a array to function and that function will add some elements to that array or will
remove some elements from array, then you will select NSMutableArray. When you dont want to
change you data, then you store it into NSArray. For example, the country names you will put into
NSArray so that no one can accidentally modify it.
* How is the app delegate is declared by Xcode project templates?
Ans. App delegate is declared as a subclass of UIResponder by Xcode project templates.
-
7/28/2019 iPhone Interview Questions (1)
9/25
* What is the purpose of UIWindow object?
Ans. The presentation of one or more views on a screen is coordinated by UIWindow object.
* Whats the difference between frame and bounds?
Ans. The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height)
relative to the superview it is contained within. The bounds of a view is the rectangle, expressed asa location (x,y) and size (width,height) relative to its own coordinate system (0,0).
* What is @interface?
Ans. Its a keyword used to declare the Class.
* What is @implementation?
Ans. Its a keyword used to define the Class.
* Garbage collector in iPhone?
Ans. iOS 5.0 has got the ARC ( Automated reference counting ). Objective C does not have a
garbage collector rather it uses the reference counting algorithm to manage the memory. This wasthe developers task until Apple launched iOS 5.0. Again if you are targeting iOS 4.0 or earlier ,
ARC is no more a choice for you.
* What is delegate?
Ans. Delegate is an object that handles the events happening on an object. To do that delegate has
to follow a protocol specifying the task it is going to handle .
* What is @synthesize?
Ans. We use @synthesize to generate getters and setters automatically from compiler. We declare
properties and then generate getter and setter method by using @synthesize.
* What are the features of iOS 6.0 ?
Ans. Please hit on this link-
https://developer.apple.com/technologies/ios6/
* What is nonatomic ?
Ans. nonatomic and atomic are related to multithreading environment . If a property has an
attribute as nonatomic that means multiple threads can modify that property concurrently. If the
attribute is atomic, the threads would be given access atomically. So Atomic is thread safe
while nonatomic is thread unsafe. Atomic drastically hampers the performance so until and unlessnot needed you should never go for atomic attribute. nonatomic will do in most of the cases.
* What are the delegate methods of MKMapView ?
Ans. Firstly you have added the storeKit.framework in your xcode project then define the protocol
as in .h file.
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation;
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views;
https://developer.apple.com/technologies/ios6/https://developer.apple.com/technologies/ios6/ -
7/28/2019 iPhone Interview Questions (1)
10/25
* What are the important delegate methods of NSXML parser?
Ans.
-DidStartElement
-FoundCharecters
-DidEndElement
-FoundError
* What is @dynamic and any place where it is used ?
Ans. It tells 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.
* What are the delegate methods of MKMapView ?
Ans.1) - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
2) - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:
(MKUserTrackingMode)mode animated:(BOOL)animated
3) - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
4) - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:
(MKUserLocation *)userLocation
5) - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id < MKAnnotation >)annotation
-
7/28/2019 iPhone Interview Questions (1)
11/25
latest ios interview questionsCore Data
Core Data: it is used to store data from your iPhone application into a Sqlite file which is present in
the document directory of your application. Core Data is not a relational database, you can see Core
data as a wrapper around Sqlite although core data is quite simpler as compared to Sqlite but it does
not offer some of the functionality that Sqlite can offer and vice versa.
ManagedObject: Managed objects are the objects that are created by your application code to store
data. A managed object can be thought of as a row or a record in a relational database table. For
each new record to be added, a new managed object must be created to store the data. Similarly,
retrieved data will be returned in the form of managed objects, one for each record matching the
defined retrieval criteria. Managed objects are actually instances of the NSManagedObject class, or
a subclass thereof. These objects are contained and maintained by the managed object context.
Persistence store coordinator: The persistent store coordinator is responsible for coordinating
access to multiple persistent object stores. As an iPhone developer you will never directly interact
with the persistence store coordinator and, in fact, will very rarely need to develop an application
that requires more than one persistent object store. When multiple stores are required, the
coordinator presents these stores to the upper layers of the Core Data stack as a single store.
Managed Object Context: Core Data based applications never interact directly with the persistent
store. Instead, the application code interacts with the managed objects contained in the managed
object context layer of the Core Data stack. The context maintains the status of the objects in
relation to the underlying data store and manages the relationships between managed objects
defined by the managed object model. All interactions with the underlying database are held
temporarily in within the context until the context is instructed to save the changes, at which point
the changes are passed down through the Core Data stack and written to the persistent store.
Basics
Inheritance: Inheritance is the process of forming a new class from an existing class or base class.
The base class is also known as parent class or super class. The new class that is formed is called
derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing
the overall code size of the program, which is an important concept in object-oriented
programming.
Data Abstraction: Data Abstraction increases the power of programming language by creating user
defined data types. Data Abstraction also represents the needed information in the program withoutpresenting the details.
Data Encapsulation: Data Encapsulation combines data and functions into a single unit called
Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through
the functions present inside the class. Data Encapsulation enables the important concept of data
hiding possible.
Polymorphism: Polymorphism allows routines to use variables of different types at different times.
An operator or function can be given different meanings or functions. Polymorphism refers to a
single function or multi-functioning operator performing in different ways.
Overloading: Overloading is one type of Polymorphism. It allows an object to have different
meanings, depending on its context. When an existing operator or function begins to operate on new
http://sivasankariphone.blogspot.com/2013/01/latest-ios-interview-questions.htmlhttp://sivasankariphone.blogspot.com/2013/01/latest-ios-interview-questions.html -
7/28/2019 iPhone Interview Questions (1)
12/25
data type, or class, it is understood to be overloaded.
Reusability: This term refers to the ability for multiple programmers to use the same written and
debugged existing class of data. This is a time saving device and adds code efficiency to the
language. Additionally, the programmer can incorporate new features to the existing class, further
developing the application and allowing users to achieve increased performance. This time saving
feature optimizes code, helps in gaining secured applications and facilitates easier maintenance onthe application.
.h
Header files. Header files contain class, type, function, and constant declarations.
.m
Source files. This is the typical extension used for source files and can contain both Objective-C
and C code.
.mm
Source files. A source file with this extension can contain C++ code in addition to Objective-C and
C code. This extension should be used only if you actually refer to C++ classes or features from
your Objective-C code.
Class: A class describes the behavior and properties common to any particular type of object. Every
instance of a class shares the same properties and behavior as all other instances of that class.
Object: An object is a runtime instance of a class, and contains its own in-memory copy of the
instance variables declared by that class and pointers to the methods of the class.
Primitives: Primitive variables are variables that are not objects and carry primitive values like
numbers, Boolean etc. The primitive data types are:
int, float, bool, long, short, double, etc.,
Id Variable: id means "a reference to some random Objective-C object of unknown class"
The interface is usually in a .h file. The implementation is usually in a .m file.
A class in Objective-C can declare two types of methods: instance methods and class methods.
Inheritance: When one class inherits from another, the child inherits all the behavior and properties
defined by the parent. It also has the opportunity either to define its own additional behavior andproperties, or override the behavior of the parent.
NSObject: It is the root class of most Objective-C classes.
IPhone Application Life Cycle:
http://2.bp.blogspot.com/-9BW4tK3Tl6c/UQC5fuWJDDI/AAAAAAAAAHI/i-
bG9_erUMM/s1600/Untitled.png
UIApplication: The UIApplication class provides a centralized point of control and coordination
for applications running on IOS. Every application must have exactly one instance of UIApplication(or a subclass of UIApplication). When an application is launched, the UIApplicationMain function
is called; among its other tasks, this function creates a singleton UIApplication object. Thereafter
http://2.bp.blogspot.com/-9BW4tK3Tl6c/UQC5fuWJDDI/AAAAAAAAAHI/i-bG9_erUMM/s1600/Untitled.pnghttp://2.bp.blogspot.com/-9BW4tK3Tl6c/UQC5fuWJDDI/AAAAAAAAAHI/i-bG9_erUMM/s1600/Untitled.pnghttp://2.bp.blogspot.com/-9BW4tK3Tl6c/UQC5fuWJDDI/AAAAAAAAAHI/i-bG9_erUMM/s1600/Untitled.pnghttp://2.bp.blogspot.com/-9BW4tK3Tl6c/UQC5fuWJDDI/AAAAAAAAAHI/i-bG9_erUMM/s1600/Untitled.png -
7/28/2019 iPhone Interview Questions (1)
13/25
you can access this object by invoking the sharedApplication class method.
Interface Builder: It is a software development application for Apple's IPhone operating system. It
is part of Xcode (formerly Project Builder), the Apple Developer Connection developer's toolset.
Interface Builder allows Cocoa and Carbon developers to create interfaces for applications using a
graphical user interface. The resulting interface is stored as a .nib file
What is the Nib File: Nib files play an important role in the creation of applications in OS X and
iOS. With nib files, you create and manipulate your user interfaces graphically, using Xcode,
instead of programmatically. Because you can see the results of your changes instantly, you can
experiment with different layouts and configurations very quickly. You can also change many
aspects of your user interface later without rewriting any code.
Framework: framework is a hierarchical directory that encapsulates shared resources, such as a
dynamic shared library, nib files, image files, localized strings, header files, and reference
documentation in a single package. Multiple applications can use all of these resources
simultaneously. The system loads them into memory as needed and shares the one copy of the
resource among all applications whenever possible.Protocol: Protocol is a class, which will have reference of delegate and declaration of delegate
methods.
Delegate: Delegate is the class object, which will have definition of protocol. A delegate allows one
object to send messages to another object when an event happens. For example, if you're
downloading data from a web site asynchronously using the NSURLConnection class.
NSURLConnection has three common delegates:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
- (void)connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse
*)response
Category: Categories are a powerful feature that allows you to extend the functionality of existing
classes without subclassing. If you need to add a method to an existing class, perhaps to add
functionality to make it easier to do something in your own application, the easiest way is to use a
category.
The Foundation Framework: The Foundation framework defines a base layer of Objective-C
classes. In addition to providing a set of useful primitive object classes, it introduces severalparadigms that define functionality not covered by the Objective-C language.
The Foundation framework includes the root object class, classes
representing basic data types such as strings and byte arrays, collection classes for storing other
objects, classes representing system information such as dates, and classes representing
communication ports
For Example: NSString, NSNumber, NSArray, NSMutableArray, NSDictionary,
NSMutableDictionary, NSSet, NSMutableSet, NSData, NSMutableData, NSDate, etc.,
Immutable: This means that the internal contents must be set when an object is created, and
cannot subsequently be changed by other objects.
-
7/28/2019 iPhone Interview Questions (1)
14/25
Mutable: This means that the internal contents must not be set when an object is created, and can
subsequently be changed by other objects.
The UIKit Framework: The UIKit framework provides the classes needed to construct and
manage an applications user interface for iOS. It provides an application object, event handling,drawing model, windows, views, and controls specifically designed for a touch screen interface.
For Example: UIView, UIButton, UIImageView, UISwitch, etc.,
The Core Graphics framework: The Core Graphics framework is a C-based API that is based on
the Quartz advanced drawing engine. It provides low-level, lightweight 2D rendering with
unmatched output fidelity. You use this framework to handle path-based drawing, transformations,
color management, offscreen rendering, patterns, gradients and shadings, image data management,
image creation, masking, and PDF document creation, display, and parsing.
For Example: CGRect, CGImage, CGLayer, CGColor, etc.,
The Model-View-Controller Paradigm: The MVC design pattern considers there to be three
types of objects: model objects, view objects, and controller objects. The MVC pattern defines the
roles that these types of objects play in the application and their lines of communication.
Model: A well-designed MVC application has all its important data encapsulated in model objects.
For example, if you have a model object that represents a person (say you are writing an address
book), you might want to store a birthdate. Thats a good thing to store in your Person model object.
View: A view object knows how to display, and might allow users to edit, the data from the
applications model. The view should not be responsible for storing the data it is displaying. A view
object can be in charge of displaying just one part of a model object, or a whole model object, or
even many different model objects. Views come in many different varieties.
Controller: A controller object acts as the intermediary between the application's view objects and
its model objects. Controllers are often in charge of making sure the views have access to the model
objects they need to display and act as the conduit through which views learn about changes to the
model. Controller objects can also perform set-up and coordinating tasks for an application and
manage the life cycles of other objects.
UIViewcontrollers and Life Cycle:
ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-
time-only work
ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any
operations that you want to happen every time before the view is visible. Because you might be
going back and forth between views, this will be called every time your view is about to appear on
the screen
ViewDidAppear - Called after the view appears - great place to start an animations or the loading
of external data from an API.
ViewWill/DidDisappear - Same idea as the WillAppear.
ViewDidUnload/Dispose - Available to you, but usually not necessary in Monotouch. In objective-c, this is where you do your cleanup and release of stuff, but this is handled automatically so not
much you really need to do here.
-
7/28/2019 iPhone Interview Questions (1)
15/25
-
7/28/2019 iPhone Interview Questions (1)
16/25
several times; an object receives a release message for each time it was put into the pool (sent an
autorelease message).
Multitasking: In iOS 4 and later, multiple applications can reside in memory and run
simultaneously. Only one application runs in the foreground, while all other applications reside in
the background. Applications running in this environment must be designed to handle transitions
between the foreground and background.
Web services: Web services are the interchange of XML-based queries and responses between
clients and servers over the Internet or an intranet via standard protocols such as HTTP, HTTPS.
Selectors: In Objective-C, selector has two meanings. It can be used to refer simply to the name of
a method when its used in a source-code message to an object. It also, though, refers to the unique
identifier that replaces the name when the source code is compiled. Compiled selectors are of type
SEL. All methods with the same name have the same selector. You can use a selector to invoke a
method on an objectthis provides the basis for the implementation of the target-action design
pattern in Cocoa.
JSON: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for
humans to read and write. It is easy for machines to parse and generate.
-->
Blocks: Blocks will let you define actions that take place in response to an event, but rather than
have you write a separate method or function, they allow you to write the handling code right where
you set up the listener for that event. This can save a mess of code and make your application much
more organized.
Blocks are a useful alternative to traditional callback functions for two main reasons:
They allow you to write code at the point of invocation that is executed later in the context of the
method implementation. Blocks are thus often parameters of framework methods.
They allow access to local variables. Rather than using callbacks requiring a data structure that
embodies all the contextual information you need to perform an operation, you simply access local
variables directly.
What is the difference between the "copy" & "mutableCopy"?
MutableCopy always returns a mutable result.
Copy always returns an immutable result.
What is the difference between the "Synchronous" & " Asynchronous "? Synchronous communication refers to interaction happening in real-time a meeting or phone
conference.
Asynchronous communication happens anytime and doesnt rely on being together at the same
time in person or electronically. E-mail is a good example of asynchronous communication.
-
7/28/2019 iPhone Interview Questions (1)
17/25
ios interview questions1. What is property?
Ans : Properties are used to access the instance variables from outside of the class.
2. What is Synthesized?
Ans : After you declare the property in obj-c we have to tell the compiler instantly by using
synthesize directive. Actually this tell to compiler generate a getter and setter message.
3. What is non-atomic,alloc,init,new,copy,atomic?Ans : nonatomic : A nonatomic property means that when the property will be written(ex during a
set call) no lock will be added on the variable synthesized by this property(that means no overkill
time consuming @synchronize). To avoid conflict the multithreading.
atomic : Is default behavior, will ensure the present process is completed by the cpu, before
another process access the variable, not fast, as it ensures the process is completed entirely.
alloc : alloc is a Class selector (that is for exemple called like)
init : To complete the initialization, you must call the proper designated initializer on the
instance itself
new : The new basically does an alloc -> init except it is called directly at class level
copy : A copy property means that when you modify that property
4. What is Webservices?
Ans : The purpose is to expose the data in the form of xml format, by using this we can getting the
data from server.
5. What is Parsing?
Ans : To access the data in the xml element is called parser. In xml parsing we are using
NSXMLParser class. Mostly two types of parsers those are SAX and DOM, in iPhone we are using
SAX parser.
SAX : "Event driven parser", when we will work this parser take only reference from xml
parser and generate the one event every time.
DOM : "document based parser", when we will work this parser all the data of xml is stored
in RMN, in this parser memory consumption is more.After parsing we want to get your data from xml parser using delegate methods those are :
did start element
did end element
found characters
6. Which class is used to establish connection between application to web server?
Ans : NSURL, NSURLREQUEST, NSURLCONNECTION.
After we are calling NSURLConnectionDelegate methods :
connection did receive response,
connection did receive data,
connection fail with error,
connection did finish loading.7. What is JSON Parser?
Ans : JSON means "java script object notation". This is one type of parser, test based and
lightweight parser.
8. By default application which things contains?
Ans : In iPhone application by default having 3 things :
a) main() : it is entry point of application.
b) Appdelegate : it is perform the basic application and functionality.
c) Window : it is provided uiinterface.
UIViewController is a base class for all controllers.
9. What is the navigation controller?
Ans : Navigation controller contains the stack of controllers every navigation controller must behaving root view controller by default those controllers contains 2 methods:
a) PushVew b) PopView
http://sivasankariphone.blogspot.com/2013/01/ios-interview-questions.htmlhttp://sivasankariphone.blogspot.com/2013/01/ios-interview-questions.html -
7/28/2019 iPhone Interview Questions (1)
18/25
By default navigation controller contains tableView.
10. What is the tabbar controller?
Ans : Tabbar is used to common way to display the data on iphone.
11. What is TableView Controller?
Ans : The tableview controller contains the number is of rows and columns visible in the
applicatoon and makes a cell editable or not as a response to key press.
The TableView contains 2 delegate protocols:a) UITableViewDataSource.
b) UITableViewDelegate.
By default table view controller contains DetailViewController.
12. What is the split view controller?
Ans : This controller is used for iPad application and it contains proper controllers by default split
view controller contains root view controller and detail view controller.
13. Tell me about the MVC architecture?
Ans : M :- model V :- view C :- controller
Main advantages of MVC architecture is provide "reausability and security" by separating
the layer by using MVC architecture.
Model : it is a class modal is interact with database.View : display the information in view.
Controller : controller is used for by getting the data from model and controls the views.
14. What is the difference between instance methods and class methods?
Ans : Class Methods : are methods which are declared as static. The method can be called
without creating an instance of the class. Class methods can only operate on class members and not
on instance members as class methods are unaware of instance members. Instance methods of the
class can also not be called from within a class method unless they are being called on an instance
of that class.
Instance Methods : on the other hand require an instance of the class to exist before they
can be called, so an instance of a class needs to be created by using the new keyword. Instance
methods operate on specific instances of classes. Instance methods are not declared as static.
Instance methods followed by member variable.
15. What is data encapsulation?
Ans : Data is contain with is objects and is not accessible by any other than via methods defined
on the class is called data encapsulation.
16. What is accessory methods?
Ans : Accessory methods are methods belonging to a class that allow to get and set the values of
instance valuables contained with the class.
17. What is the single inheritance in obj-c?
Ans : Obj-c subclass can only be derived from a single direct parent class this concept is called as
single inheritance.18. What is the difference between NSString and NSMutableString?
Ans : NSString : the length is fixed can't append another string.
NSMutableString : it can append another string.
19. What is delegate?
Ans : The helper object is called delegate. A delegate allows one object to send messages to
another object when an event happens. For example, if you're downloading data from a web site
asynchronously using theNSURLConnection class. NSURLConnection has three common
delegates:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
- (void)connectionDidFinishLoading:(NSURLConnection *)connection- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse
*)response
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.htmlhttp://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html -
7/28/2019 iPhone Interview Questions (1)
19/25
20. What is Protocol? Types off protocols?
Ans : List of methods that shared among the class.
Types of protocols :
Formal Protocols : required, optional
Informal Protocol : Categories.
Categories allow you to add functionality to already existing class without extending them.
21. Is it supports multiple inheritance?Ans : Not supported.
22. What is memory management?
Ans : It allocates and reallocates memory and find out memory leaks.
23. What is singleton?
Ans : Singleton are a class that only gets instantiated once in your applications run time.
24. How many layers are there in iPhone?
Ans : Cocoa touch layer.
media layer.
core service layer.
core os layer.
25. What are the design patterns?Ans : a. MVC
b. Singleton : A system only needs to create one instance of a class, and that instance
will be accessed throughout the program.
c. Factory design pattern.
26. Explain about Development steps?
Ans : a. Open application - UiTitles - Key chain access - certificate assistance - requested a
certificate from a certificate authority. Email, Save to disk enter OK then certificate icon is created
in desktop,
b. Upload the developer certificate into developer.apple.com
c. Create the provisioning profile from developer.apple.com and download it to system.
open the Xcode and select the window -> organized -> organized -> select the device and under
provisioning profile tab drag it to device.
27. What are the access specifiers in obj-c?
Ans : Protected (default), public, private, package.
28. What is the difference between poptorootviewcontroller and poptoviewcontroller?
Ans : poptorootviewcontroller: go to the last-view.
poptoviewcontroller : go to root view.
29. What is the difference between frame and bounds?
Ans : Frame A view's frame (CGRect) is the position of its rectangle in the superview's coordinate
system. By default it starts at the top left.
Bounds A view's bounds (CGRect) expresses a view rectangle in its own coordinate system.http://cocoainterviews.blogspot.in/
iPhone Interview Questions and Answers
http://cocoainterviews.blogspot.in/http://cocoainterviews.blogspot.in/ -
7/28/2019 iPhone Interview Questions (1)
20/25
1. What is @interface?
- Its a keyword used to declare the Class.
2. What is @implementation?
Its a keyword used to define the Class.
3. Garbage collector in iPhone?
- iOS 5.0 has got the ARC ( Automated reference counting ). Objective C does not have a garbage
collector rather it uses the reference counting algorithm to manage the memory. This was the
developers task until Apple launched iOS 5.0. Again if you are targeting iOS 4.0 or earlier , ARC is
no more a choice for you .
4. What is delegate?
- Delegate is an object that handles the events happening on an object. To do that delegate has to
follow a protocol specifying the task it is going to handle .
5. What is @synthesize?
- We use @synthesize to generate getters and setters automatically from compiler. We declare
properties and then generate getter and setter method by using @synthesize.
6. What are the features of iOS 5.0 ?
- https://developer.apple.com/technologies/ios5/
7. What is nonatomic ?
- nonatomic and atomic are related to multithreading environment .
- If a property has an attribute as nonatomic that means multiple threads can modify that property
concurrently.
- If the attribute is atomic, the threads would be given access atomically.
- So Atomic is thread safe while nonatomic is thread unsafe.
- Atomic drastically hampers the performance so until and unless not needed you should never go
for atomic attribute. nonatomic will do in most of the cases.
8. What are the delegate methods of MKMapView ?
-
7/28/2019 iPhone Interview Questions (1)
21/25
- Check the MKMapViewDelegate in the Documentation. If you dont have Xcode with you then
search on Google.
9. What are the important delegate methods of NSXML parser?
-DidStartElement
-FoundCharecters
-DidEndElement
-FoundError
10. What is @dynamic and any place where it is used ?
- It tells 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.
11. What is @property?
- It is a keyword used to declare a property.
12. What is data source?
- The datasource is an object that implements the required datasource protocol that is needed to
create a complex control.
Ex UITableView is a view that needs a datasource object to which will help building the table.
Often its the controller that is displaying the table view. The protocol that dataSource object
( mostly controller it self) has to implement is UITableViewDataSource .
13. What is model view controller?
- MVC is a Design pattern .
-
7/28/2019 iPhone Interview Questions (1)
22/25
Model stands for the database object which will manage all the database transaction .
- View stands for the UI i.e. the UI visible to the user. User will be interacting with the view.
- Controller is an object who handles the view events and also render the database changes to the
UI. In short , it bridges the interaction between Modal and View.
14. what is @ protocol?
- @protocol is a keyword used to define a protocol. A protocol is a set of method declarations
defining specific purpose. It only lists out the methods prototype , the actual implantation would be
provided by the class that implements / follows the protocol.
15. what is id?
- id is a generic reference type. The variable declared using id data-type can hold any object. Most
of the methods that returns an object has id as return type. Ex init.
16. Explain memory management?
- Most of the object oriented languages have the Garbage Collector . All the objects are allocated
on the heap memory. The Garbage Collector is a thread that runs periodically to check all the
objects, which are no more being referenced from the program. Garbage collector then de-allocates
all these unreferenced objects on the Heap. In this environment programmer does not need to worry
about de-allocating the objects explicitly.
In Objective C we dont have garbage collector. ( Note: Its available from iOS 5.0 only). So in
this environment we have to explicitly take care of allocation and deallocation of all the objects in
our program. And to manage this Objective C uses reference counting algorithm as the memory
management algorithm.
Reference Counting: In this algorithm every object keeps track of it owners ( I,e reference variables
from the program ) . No of owners is represented by the property retainCount declared in NSObject.
If this retainCount goes to 0 the object gets deallocated automatically. We never call dealloc
method on any object explicitly.
17. what is retain and release?
- retain and release are two method defined in NSObject . - -
-
7/28/2019 iPhone Interview Questions (1)
23/25
- These methods are related to Memory Mangement .
- retain method when called increases the retainCount by 1.
- release method when called decreases the retainCount by 1
18. what is dealloc?
- dealloc method is called on an object to actually deallocate the memory for that object. ( We
should never call dealloc directly )
- In reference counting environment when retainCount of an object reaches to 0, the dealloc
method is called on that object automatically to delete the memory space of the object .
- If the object is having some reference type variable holding other objects, then we should call
release method on every variable in dealloc.
- If you override then [super dealloc] should be the last line in this method.
19. What is Autorelease pool?
- Autorelease pool is like a container that holds the autoreleased objects .
- This pool is drained with every run-loop of the Application
- When the pool gets drained, autorelease pool sends a release message to all the objects it was
holding.
20. What is Foundation Framework? Can you explain some classes from that?
- Foundation is one of the important frameworks in COCOA Touch.
- It contains the classes like NSArray , NSString , NSObject etc .
21. What is the difference between NSArray and NSMutableArray?
* NSArray
- is a static array
- Once created you can not modify the array
- Ex you can not add or remove the object in NSArray.
* NSMutableArray
-
7/28/2019 iPhone Interview Questions (1)
24/25
- is a dynamic array
- You can add or remove the object dynamically.
22. Write a delegate method of the table view?
- (void)tableView:( UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
23. What are the delegate methods of NSURLConection?
- didReceiveResponse:
- didReceiveData:
- didFinishLoadingData:
- didFailWithError:
24. What is cocoa ?
- COCOA is a collection of frameworks used to write Applications for MAC OS X.
25. Singleton classes
- A singleton class is such a class from which no more that one instance can be created. So there
will always be single instance created throughout the program.
Ex UIApplication.
Delegate & protocol
http://www.tutorialspoint.com/ios/ios_delegates.htm
DELEGATE AND PROTOCOL
-
7/28/2019 iPhone Interview Questions (1)
25/25
-----------------------------------------
I'll try and explain delegation for you. It's really simple when you do know, but it takes time to get
your head around it!
Let's say you have two classes, a Calculator class that performs calculations and a CalculatorScreen
class that is used to present the result of a calculation to a user. The Calculator class should tell theCalculatorScreen when it has finished performing a calculation so the latter can update the UI.
A protocol provides a way to define a set of methods that are somehow related with a specified
name. You could have a number of methods definedin a protocol called CalculatorDelegate in the
Calculator class, but the method implementations are defined elsewhere.
The class that defines the protocol (in this case Calculator) can tell a delegate (an object that
conforms to the protocol - in this case CalculatorScreen) to implement the method. The calculator
class might finish an addition calculation and tell its delegate (the screen) to update. You get me?
Sorry, as I was writing I realized it is hard to explain and sympathized with every author that hastried!
iOS Example: When you set up a table on the iPad's display, you use the UITableView class. But
that class doesn't know what the title of the table is, or how many sections and rows it is to have, or
what to fill it with. So it delegates that responsibility to you by defining protocols called
UITableViewDataSource and UITableViewDelegate. When the UITableView needs to know some
information, for example, number of rows, it calls the appropriate method on the delegate (your
own class), the delegate class contains the implementation of those methods defined in the protocol.