iOS Interview Questions -Part i
iOS Interview Questions -Part ii
iOS Interview Questions -Part iii
iOS Interview Questions -Part iv
iOS Interview Questions -Part v
iOS Interview Questions -Part vi
iOS Interview Questions -Part vii
iOS Interview Questions -Part viii
iOS Interview Questions -Part ix
iOS Interview Questions -Part ii
iOS Interview Questions -Part iii
iOS Interview Questions -Part iv
iOS Interview Questions -Part v
iOS Interview Questions -Part vi
iOS Interview Questions -Part vii
iOS Interview Questions -Part viii
iOS Interview Questions -Part ix
166.What are all the difference between categories and subclasses?Why should we go to subclasses?
Category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category. The methods in the category become part of the class type and are inherited by all the class’s subclasses.As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.The Cocoa frameworks define numerous categories, most of them informal protocols . Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:
You cannot add instance variables to the class.
If you override existing methods of the class, your application may behave unpredictably.
167.What is notification in iOS?
The notification mechanism of Cocoa implements one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects—the observed object—creates a notification object and posts it to a notification center. The notification center determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, which contains the notification name, the observed object, and a dictionary containing any supplemental information.Posting a notification is a synchronous procedure. The posting object doesn’t regain control until the notification center has broadcast the notification to all observers. For asynchronous behavior, you can put the notification in a notification queue; control returns immediately to the posting object and the notification center broadcasts the notification when it reaches the top of the queue.Regular notifications—that is, those broadcast by the notification center—are intraprocess only. If you want to broadcast notifications to other processes, you can use the istributed notification center and its related API.
168.What is the difference between delegates and notifications?
We can use notifications for a variety of reasons. For example, you could broadcast a notification to change how user-interface elements display information based on a certain event elsewhere in the program. Or you could use notifications as a way to ensure that objects in a document save their state before the document window is closed. The general purpose of notifications is to inform other objects of program events so they can respond appropriately.But objects receiving notifications can react only after the event has occurred. This is a significant difference from delegation. The delegate is given a chance to reject or modify the operation proposed by the delegating object. Observing objects, on the other hand, cannot directly affect an impending operation.
169.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. There are some restrictions on which classes can pose:
A class may only pose as one of its direct or indirect superclasses
The posing class must not define any new instance variables which are absent from the target class (though it may define or override methods).
No messages must have been sent to the target class prior to the posing.
Posing, similarly to categories, allows globally augmenting existing classes. Posing permits two features absent from categories:
A posing class can call overridden methods through super, thus incorporating the implementation of the target class.
A posing class can override methods defined in categories.
170.What is atomic and nonatomic? Which one is safer? Which one is default?
You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)nonatomic Specifies that accessors are nonatomic. By default, accessors are atomic.
Properties are atomic by default so that synthesized accessors provide robust access to properties in a multithreaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently.
If you specify strong, copy, or retain and do not specifynonatomic, then in a reference-counted environment, a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value—the implementation will be similar to the following:
[_internal lock]; // lock using an object-level lock
|
id result = [[value retain] autorelease];
|
[_internal unlock];
|
return result;
|
If you specify nonatomic, a synthesized accessor for an object property simply returns the value directly.
171.Where can you test Apple iPhone apps if you don’t have the device?
iOS Simulator can be used to test mobile applications. Xcode tool that comes along with iOS SDK includes Xcode IDE as well as the iOS Simulator. Xcode also includes all required tools and frameworks for building iOS apps. However, it is strongly recommended to test the app on the real device before publishing it.
173.Which JSON framework is supported by iOS?
SBJson framework is supported by iOS. It is a JSON parser and generator for Objective-C. SBJson provides flexible APIs and additional control that makes JSON handling easier.
174.What are the tools required to develop iOS applications?
iOS development requires Intel-based Macintosh computer and iOS SDK.
175.Name the framework that is used to construct application’s user interface for iOS.
The UIKit framework is used to develop application’s user interface for iOS. UIKit framework provides event handling, drawing model, windows, views, and controls specifically designed for a touch screen interface.
176.Name the application thread from where UIKit classes should be used?
UIKit classes should be used only from an application’s main thread. Note: The derived classes of UIResponder and the classes which manipulate application’s user interface should be used from application’s main thread.
177.Which API is used to write test scripts that help in exercising the application’s user interface elements?
UI Automation API is used to automate test procedures. Tests scripts are written in JavaScript to the UI Automation API. This in turn simulates user interaction with the application and returns log information to the host computer.
178.Why an app on iOS device behaves differently when running in foreground than in background?
An application behaves differently when running in foreground than in background because of the limitation of resources on iOS devices.
179.How can an operating system improve battery life while running an app?
An app is notified whenever the operating system moves the apps between foreground and background. The operating system improves battery life while it bounds what your app can do in the background. This also improves the user experience with foreground app.
180.Which framework delivers event to custom object when app is in foreground?
The UIKit infrastructure takes care of delivering events to custom objects. As an app developer, you have to override methods in the appropriate objects to process those events.
182.When an app is said to be in not running state?
An app is said to be in ‘not running’ state when:
- it is not launched.
- it gets terminated by the system during running.
183.Assume that your app is running in the foreground but is currently not receiving events. In which sate it would be in?
An app will be in InActive state if it is running in the foreground but is currently not receiving events. An app stays in InActive state only briefly as it transitions to a different state.
184.Give example scenarios when an application goes into InActive state?
An app can get into InActive state when the user locks the screen or the system prompts the user to respond to some event e.g. SMS message, incoming call etc.
185.When an app is said to be in active state?
An app is said to be in active state when it is running in foreground and is receiving events.
186.Name the app sate which it reaches briefly on its way to being suspended
An app enters background state briefly on its way to being suspended.
187.Assume that an app is not in foreground but is still executing code. In which state will it be in?
Background state.
188.An app is loaded into memory but is not executing any code. In which state will it be in?
An app is said to be in suspended state when it is still in memory but is not executing any code.
189.Assume that system is running low on memory. What can system do for suspended apps?
In case system is running low on memory, the system may purge suspended apps without notice.
190.How can you respond to state transitions on your app?
On state transitions can be responded to state changes in an appropriate way by calling corresponding methods on app’s delegate object.
For example: applicationDidBecomeActive method can be used to prepare to run as the foreground app.
applicationDidEnterBackground method can be used to execute some code when app is running in the background and may be suspended at any time.
applicationWillEnterForeground method can be used to execute some code when your app is moving out of the background
applicationWillTerminate method is called when your app is being terminated.
191.List down app’s state transitions when it gets launched.
Before the launch of an app, it is said to be in not running state.
When an app is launched, it moves to the active or background state, after transitioning briefly through the inactive state.
192.Who calls the main function of you app during the app launch cycle?
During app launching, the system creates a main thread for the app and calls the app’s main function on that main thread. The Xcode project’s default main function hands over control to the UIKit framework, which takes care of initializing the app before it is run.
193.What is the use of controller object UIApplication?
Controller object UIApplication is used without subclassing to manage the application event loop.
It coordinates other high-level app behaviors.
It works along with the app delegate object which contains app-level logic.
194.Which object is create by UIApplicationMain function at app launch time?
The app delegate object is created by UIApplicationMain function at app launch time. The app delegate object’s main job is to handle state transitions within the app.
195.How is the app delegate is declared by Xcode project templates?
App delegate is declared as a subclass of UIResponder by Xcode project templates.
196.What happens if IApplication object does not handle an event?
In such case the event will be dispatched to your app delegate for processing.
197.Which app specific objects store the app’s content?
Data model objects are app specific objects and store app’s content. Apps can also use document objects to manage some or all of their data model objects.
198.Are document objects required for an application? What does they offer?
Document objects are not required but are very useful in grouping data that belongs in a single file or file package.
FabGreenTechnologies-Madivala
FabGreenTech.com
FabGreenTech.com
No comments:
Post a Comment