Objective C Questions

download Objective C Questions

of 15

Transcript of Objective C Questions

  • 8/9/2019 Objective C Questions

    1/37

    1-How would you create your own custom view?

    By Subclassing the UIView class.

    2-Whats fast enumeration?

    Fast enumeration is a language feature that allows you toenumerate over the contents of a collection. (Your code will alsorun faster because the internal implementation reducesmessagesend overhead and increases pipelining potential.

    3-Whats a struct?

     ! struct is a special " data type that encapsulates other pieces

    of data into a single cohesive unit. #i$e an ob%ect& but built into".

    4-What are mutable and immutable types in Objective ?

    'utable means you can change its contents later but when youmar$ any ob%ect immutable& it means once they are initialied&their values cannot be changed. For e)ample& *S!rray& *SStringvalues cannot be changed after initialied.

    !-"#plain retain counts.

    +etain counts are the way in which memory is managed in,b%ective-". hen you create an ob%ect& it has a retain count of/. hen you send an ob%ect a retain message& its retain count isincremented by /. hen you send an ob%ect a release message&its retain count is decremented by /. hen you send an ob%ect aautorelease message& its retain count is decremented by / atsome stage in the future. If an ob%ectʼs retain count is reduced

    to 0& it is deallocated.

    $-Whats the difference between frame and bounds?

    1he frame of a view is the rectangle& e)pressed as a location()&y and sie (width&height relative to the superview it iscontained within. 1he bounds of a view is the rectangle&e)pressed as a location ()&y and sie (width&height relative toits own coordinate system (0&0.

    %-&s a dele'ate retained?

  • 8/9/2019 Objective C Questions

    2/37

    *o& the delegate is never retained2 3ver2

    (-Outline the class hierarchy for a )&*utton until +,Object

    UIButton inherits from UI"ontrol& UI"ontrol inherits fromUIView& UIView inherits from UI+esponder& UI+esponder inherits from the root class *S,b%ect

    .- What is dynamic?

    You use the @dynamic $eyword to tell the compiler that you will fulfill the !4I contract implied by a property either by providingmethod implementations directly or at runtime using othermechanisms such as dynamic loading of code or dynamic method

    resolution. It suppresses the warnings that the compiler wouldotherwise generate if it can5t find suitable implementations. Youshould use it only if you $now that the methods will be availableat runtime

    1/-&f & call perform,elector0withObject0afterelay0 is theobject retained?

    Yes& the ob%ect is retained. It creates a timer that calls a

    selector on the current threads run loop. It may not be /006 precise time-wise as it attempts to de7ueue the message fromthe run loop and perform the selector.

    11-an you e#plain what happens when you call autoreleaseon an object?

    hen you send an ob%ect a autorelease message& its retain countis decremented by / at some stage in the future. 1he ob%ect isadded to an autorelease pool on the current thread. 1he mainthread loop creates an autorelease pool at the beginning of the function& and release it at the end. 1his establishes a pool forthe lifetime of the tas$. 8owever& this also means that anyautoreleased ob%ects created during the lifetime of the tas$ arenot disposed of until the tas$ completes. 1his may lead to thetas$ʼs memory footprint increasing unnecessarily. You can alsoconsider creating pools with a narrower scope or use*S,peration9ueue with itʼs own autorelease pool. (!lsoimportant : You only release or autorelease ob%ects you own.

    12-Whats the +,oder class used for?

  • 8/9/2019 Objective C Questions

    3/37

    *S"oder is an abstract"lass which represents a stream of data. 1heyare used in !rchiving and Unarchiving ob%ects. *S"oder ob%ects areusually used in a method that is being implemented so that the classconforms to the protocol. (which has something li$e encode,b%ectand decode,b%ect methods in them.

    13-Whats an +,Operationueue and howwould you use it?

    1he *S,peration9ueue class regulates the e)ecution of a set of*S,peration ob%ects. !n operation 7ueue is generally used to perform some asynchronous operations on a bac$ground threadso as not to bloc$ the main thread.

    14-"#plain the correct way to mana'e Outlets memory

    "reate them as properties in the header that are retained. Inthe view;idUnload set the outlets to nil(i.e self.outlet < nil.Finally in dealloc ma$e sure to release the outlet.

    1!-&s the dele'ate for a 55nimation retained?

    Yes it is22 1his is one of the rare e)ceptions to memorymanagement rules.

    1$-What happens when the followin' code e#ecutes?

    *all 6ball 7 8888*all alloc9 init9 autorelease9 autorelease9:

    It will crash because itʼs added twice to the autorelease pooland when it it de7ueued the autorelease pool calls release morethan once.

    1%-"#plain the difference between +,Operationueueconcurrent and non-concurrent

    In the conte)t of an *S,peration ob%ect& which runs in an*S,peration9ueue& the terms concurrent and non-concurrent donot necessarily refer to the side-by-side e)ecution of threads.Instead& a non-concurrent operation is one that e)ecutes usingthe environment that is provided for it while a concurrentoperation is responsible for setting up its own e)ecutionenvironment.

    1(-&mplement your own synthesi;ed methods for the property+,,trin' 6title

  • 8/9/2019 Objective C Questions

    4/37

    ell you would want to implement the getter and setter for the titleob%ect. Something li$e this= view source print> - (*SString? title @@ Aetter method  return titleC

     D- (void set1itle= (*SString? new1itle @@Setter method  if (new1itle 2< title Etitle releaseCtitle < Enew1itle retainC @@ ,r copy& depending on your needs.

     D D

    1.-&mplement the followin' methods0 retain< release< autorelease-(idretain *SIncrement3)tra+ef"ount(selfCreturn selfC

     D-(voidrelease if(*S;ecrement3)tra+ef"ountasGero(self

     *S;eallocate,b%ect(selfC

     D D-(idautorelease @@ !dd the ob%ect to the autorelease poolE*S!utorelease4ool add,b%ect=selfCreturn self 20-What are the App states. Explain them?

    H Not running State= 1he app has not been launched or was running but

    was terminated by the system.H Inactive state: 1he app is running in the foreground but is currently

    not receiving events. (It may be e)ecuting other code though. !n appusually stays in this state only briefly as it transitions to a differentstate. 1he only time it stays inactive for any period of time is whenthe user loc$s the screen or the system prompts the user to respondto some event& such as an incoming phone call or S'S message.

    H  Active state= 1he app is running in the foreground and is receivingevents. 1his is the normal mode for foreground apps.

    H Bacgroun! state= 1he app is in the bac$ground and e)ecuting code.

    'ost apps enter this state briefly on their way to being suspended.8owever& an app that re7uests e)tra e)ecution time may remain in

  • 8/9/2019 Objective C Questions

    5/37

    this state for a period of time. In addition& an app being launcheddirectly into the bac$ground enters this state instead of the inactivestate. For information about how to e)ecute code while in thebac$ground& see Bac$ground 3)ecution and 'ultitas$ing.J

    H Suspen!e! state:1he app is in the bac$ground but is not e)ecutingcode. 1he system moves apps to this state automatically and does notnotify them before doing so. hile suspended& an app remains inmemory but does not e)ecute any code. hen a low-memorycondition occurs& the system may purge suspended apps withoutnotice to ma$e more space for the foreground app.

    21-What is 5utomatic =eference ountin' >5= ?

     !+" is a compiler-level feature that simplifies the process ofmanaging the lifetimes of ,b%ective-" ob%ects. Instead of you

    having to remember when to retain or release an ob%ect& !+"evaluates the lifetime re7uirements of your ob%ects andautomatically inserts the appropriate method calls at compiletime.

    22-@ultitasAin' support is available from which version?

    i,S K and above supports multi-tas$ing and allows apps toremain in the bac$ground until they are launched again or untilthey are terminated.

    23-How many bytes we can send to apple push notificationserver

    LMNbytes.

    24-What is the difference between retain B assi'n? Assign creates a reference from one ob%ect to another withoutincreasing the source5s retain count.if (_variable != object){[_variable release];

     _variable = nil; _variable = object;}

    "etain creates a reference from one ob%ect to another and increasesthe retain count of the source ob%ect.if (_variable != object){ [_variable release];

     _variable = nil;

     _variable = [object retain];}

  • 8/9/2019 Objective C Questions

    6/37

    2!-Why do we need to use C,ynthesi;e?e can use generated code li$e nonatomic& atmoic& retain withoutwriting any lines of code. e also have getter and setter methods. 1ouse this& you have L other ways= Osynthesie or Odynamic=Osynthesie& compiler will generate the getter and setterautomatically for you& Odynamic= you have to write themyourself.Oproperty is really good for memory management& fore)ample= retain.8ow can you do retain without Oproperty> if (_variable != object){[_variable release];

     _variable = nil; _variable = [object retain];}

    8ow can you use it with Oproperty> self.variable = object; hen weare calling the above line& we actually call the setter li$e EselfsetVariable=ob%ect and then the generated setter will do its %ob

    2$-What is cate'ories in iO,? ! "ategory is a feature of the ,b%ective-" language that enables youto add methods (interface and implementation to a class withouthaving to ma$e a subclass. 1here is no runtime differencePwithin thescope of your programPbetween the original methods of the classand the methods added by the category. 1he methods in the categorybecome part of the class type and are inherited by all the class5ssubclasses.!s with delegation& categories are not a strict adaptationof the ;ecorator pattern& fulfilling the intent but ta$ing a different

     path to implementing that intent. 1he behavior added by categoriesis a compile-time artifact& and is not something dynamicallyac7uired. 'oreover& categories do not encapsulate an instance of theclass being e)tended.

    2%-What is ele'ation in iO,?;elegation is a design pattern in which one ob%ect sends messages toanother ob%ectPspecified as its delegatePto as$ for input or to notify it that an event is occurring. ;elegation is often used as analternative to class inheritance to e)tend the functionality ofreusable ob%ects. For e)ample& before a window changes sie& it as$sits delegate whether the new sie is o$. 1he delegate replies to thewindow& telling it that the suggested sie is acceptable or suggestinga better sie. (For more details on window resiing& seethewindowillesi"e#to$i"e# message.;elegate methods aretypically grouped into a protocol. ! protocol is basically %ust a list of

    methods. 1he delegate protocol specifies all the messages an ob%ectmight send to its delegate. If a class conforms to (or adopts a

    https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSWindowDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSWindowDelegate/windowWillResize:toSize:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSWindowDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSWindowDelegate/windowWillResize:toSize:

  • 8/9/2019 Objective C Questions

    7/37

     protocol& it guarantees that it implements the re7uired methods of a protocol. (4rotocols may also include optional methods.In thisapplication& the application ob%ect tells its delegate that the mainstartup routines have finished by sending itthea%%lication&id'inisa*ncin+# message. 1he delegate is thenable to perform additional tas$s if it wants.

    2(-How can we achieve sin'leton pattern in iO,?1he Singleton design pattern ensures a class only has one instance&and provides a global point of access to it. 1he class $eeps trac$ of itssole instance and ensures that no other instance can be created.Singleton classes are appropriate for situations where it ma$es sense

     for a single ob%ect to provide access to a global resource.Several"ocoa framewor$ classes are singletons. 1hey include ,$'ile-ana+er&

    ,$ors%ace& ,$/%%lication& and& in UIQit& 01/%%lication. ! processis limited to one instance of these classes. hen a client as$s theclass for an instance& it gets a shared instance& which is laily created upon the first re7uest.

    2.-What is dele'ate pattern in iO,?;elegation is a mechanism by which a host ob%ect embeds a wea$reference (wea$ in the sense that it5s a simple pointer reference&unretained to another ob%ectPits delegatePand periodically sendsmessages to the delegate when it re7uires its input for a tas$. 1he

    host ob%ect is generally an off-the-shelfJ framewor$ ob%ect (such asan ,$indow or ,$2-3arserob%ect that is see$ing to accomplishsomething& but can only do so in a generic fashion. 1he delegate&which is almost always an instance of a custom class& acts incoordination with the host ob%ect& supplying program-specificbehavior at certain points in the tas$ (see Figure K-R. 1husdelegation ma$es it possible to modify or e)tend the behavior ofanother ob%ect without the need for subclassing.+efer= delegate

     pattern

    3/-What are all the difference between cate'ories and subclasses?Why should we 'o to subclasses?"ategory is a feature of the ,b%ective-" language that enables you toadd methods (interface and implementation to a class withouthaving to ma$e a subclass. 1here is no runtime differencePwithin thescope of your programPbetween the original methods of the classand the methods added by the category. 1he methods in the categorybecome part of the class type and are inherited by all the class5ssubclasses.!s with delegation& categories are not a strict adaptationof the ;ecorator pattern& fulfilling the intent but ta$ing a different

     path to implementing that intent. 1he behavior added by categoriesis a compile-time artifact& and is not something dynamically

    https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSApplicationDelegate/applicationDidFinishLaunching:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/cl/NSFileManagerhttps://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/cl/UIApplicationhttps://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/occ/cl/NSXMLParserhttps://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSApplicationDelegate/applicationDidFinishLaunching:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/cl/NSFileManagerhttps://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/cl/UIApplicationhttps://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/occ/cl/NSXMLParser

  • 8/9/2019 Objective C Questions

    8/37

    ac7uired. 'oreover& categories do not encapsulate an instance of theclass being e)tended.1he "ocoa framewor$s define numerouscategories& most of them informal protocols . ,ften they usecategories to group related methods. You may implement categoriesin your code to e)tend classes without subclassing or to group related methods. 8owever& you should be aware of these caveats=

    H You cannot add instance variables to the class.H If you override e)isting methods of the class& your application may

    behave unpredictably.

    31-What is notification in iO,?

    1he notification mechanism of "ocoa implements one-to-manybroadcast of messages based on the ,bserver pattern. ,b%ects ina program add themselves or other ob%ects to a list of observers

    of one or more notifications& each of which is identified by a global string (the notification name. 1he ob%ect that wants tonotify other ob%ectsPthe observed ob%ectPcreates a notificationob%ect and posts it to a notification center. 1he notificationcenter determines the observers of a particular notification andsends the notification to them via a message. 1he methodsinvo$ed by the notification message must conform to a certainsingle-parameter signature. 1he parameter of the method is thenotification ob%ect& which contains the notification name& the

    observed ob%ect& and a dictionary containing any supplementalinformation.4osting a notification is a synchronous procedure.1he posting ob%ect doesn5t regain control until the notificationcenter has broadcast the notification to all observers. Forasynchronous behavior& you can put the notification in anotification 7ueueC control returns immediately to the postingob%ect and the notification center broadcasts the notificationwhen it reaches the top of the 7ueue.+egular notificationsPthatis& those broadcast by the notification centerPare intraprocess

    only. If you want to broadcast notifications to other processes&you can use the istributed notification center and its related !4I.

    32-What is the difference between dele'ates andnotifications?

    e can use notifications for a variety of reasons. For e)ample&you could broadcast a notification to change how user-interfaceelements display information based on a certain event

    elsewhere in the program. ,r you could use notifications as away to ensure that ob%ects in a document save their state before

  • 8/9/2019 Objective C Questions

    9/37

    the document window is closed. 1he general purpose ofnotifications is to inform other ob%ects of program events sothey can respond appropriately.But ob%ects receivingnotifications can react only after the event has occurred. 1his is

    a significant difference from delegation. 1he delegate is given achance to re%ect or modify the operation proposed by thedelegating ob%ect. ,bserving ob%ects& on the other hand& cannotdirectly affect an impending operation.

    33-What is posin' in iO,?

    ,b%ective-" permits a class to entirel# replace another class withinan application. 1he replacing class is said to pose asJ the targetclass. !ll messages sent to the target class are then instead received

    by the posing class. 1here are some restrictions on which classes can pose=

    H ! class may only pose as one of its direct or indirect superclassesH 1he posing class must not define any new instance variables which

    are absent from the target class (though it may define or overridemethods.

    H *o messages must have been sent to the target class prior to the posing.4osing& similarly to categories& allows glo$all# augmenting existingclasses. 4osing permits two features absent from categories=

    H ! posing class can call overridden methods through super& thusincorporating the implementation of the target class.

    H ! posing class can override methods defined in categories.

    34-What is atomic and nonatomic? Which one is safer? Whichone is default?

    You can use this attribute to specify that accessor methods are notatomic. (1here is no $eyword to denote atomic.nonatomic

    Specifies that accessors are nonatomic. By default& accessors areatomic.4roperties are atomic by default so that synthesied accessors

     provide robust access to properties in a multithreaded environmentPthat is& the value returned from the getter or set via the setter isalways fully retrieved or set regardless of what other threads aree)ecuting concurrently.If you specify stron+& co%y& or retain and do not specify nonatomic&then in a reference-counted environment& a synthesied get accessor

     for an ob%ect property uses a loc$ and retains and autoreleases the

    returned valuePthe implementation will be similar to the following=

  • 8/9/2019 Objective C Questions

    10/37

    [_internal lock]; // lock using an object-level lock

    id result = [[value retain] autorelease];

    [_internal unlock];

    return result;

    If you specify nonatomic& a synthesied accessor for an ob%ect property simply returns the value directly.

    3!-Where can you test 5pple iDhone apps if you donEt have thedevice?i,S Simulator can be used to test mobile applications. code toolthat comes along with i,S S;Q includes code I;3 as well as the i,SSimulator. code also includes all re7uired tools and framewor$s forbuilding i,S apps. 8owever& it is strongly recommended to test theapp on the real device before publishing it.

    3$-Which F,O+ frameworA is supported by iO,?SBTson framewor$ is supported by i,S. It is a TS,* parser and

     generator for ,b%ective-". SBTson provides fle)ible !4Is andadditional control that ma$es TS,* handling easier.

    3%-What are the tools reGuired to develop iO, applications?i,S development re7uires Intel-based 'acintosh computer and i,SS;Q.

    3(- +ame the frameworA that is used to construct applicationEsuser interface for iO,

     !. 1he UIQit framewor$ is used to develop application5s userinterface for i,S. UIQit framewor$ provides event handling& drawingmodel& windows& views& and controls specifically designed for a touchscreen interface.

    3.-+ame the application thread from where )&it classes should beused?UIQit classes should be used only from an application5s main thread.*ote= 1he derived classes of UI+esponder and the classes whichmanipulate application5s user interface should be used fromapplication5s main thread.

    4/- Which 5D& is used to write test scripts that help in e#ercisin'the applicationEs user interface elements?

    UI !utomation !4I is used to automate test procedures. 1ests scriptsare written in TavaScript to the UI !utomation !4I. 1his in turn

  • 8/9/2019 Objective C Questions

    11/37

    simulates user interaction with the application and returns loginformation to the host computer.

    41-Why an app on iO, device behaves differently when runnin' infore'round than in bacA'round?

     !n application behaves differently when running in foreground thanin bac$ground because of the limitation of resources on i,S devices.

    42- How can an operatin' system improve battery life whilerunnin' an app?

     !n app is notified whenever the operating system moves the appsbetween foreground and bac$ground. 1he operating system improvesbattery life while it bounds what your app can do in the bac$ground.1his also improves the user e)perience with foreground app.

    43-Which frameworA delivers event to custom object when app isin fore'round?1he UIQit infrastructure ta$es care of delivering events to customob%ects. !s an app developer& you have to override methods in theappropriate ob%ects to process those events.

    44-When an app is said to be in not runnin' state? !n app is said to be in not running5 state when=- it is not launched.

    - it gets terminated by the system during running.

    4!-5ssume that your app is runnin' in the fore'round but iscurrently not receivin' events &n which sate it would be in?

     !n app will be in In!ctive state if it is running in the foreground butis currently not receiving events. !n app stays in In!ctive state onlybriefly as it transitions to a different state.

    4$- Iive e#ample scenarios when an application 'oes into &n5ctivestate?

     !n app can get into In!ctive state when the user loc$s the screen orthe system prompts the user to respond to some event e.g. S'Smessage& incoming call etc.

    4%-When an app is said to be in active state? !n app is said to be in active state when it is running in foregroundand is receiving events.

    4(-+ame the app sate which it reaches briefly on its way to bein'suspended

     !n app enters bac$ground state briefly on its way to beingsuspended.

  • 8/9/2019 Objective C Questions

    12/37

    4.- 5ssume that an app is not in fore'round but is still e#ecutin'code &n which state will it be in?Bac$ground state.

    !/-5n app is loaded into memory but is not e#ecutin' any code &nwhich state will it be in?

     !n app is said to be in suspended state when it is still in memory butis not e)ecuting any code.

    !1-5ssume that system is runnin' low on memory What can systemdo for suspended apps?In case system is running low on memory& the system may purgesuspended apps without notice.

    !2- How can you respond to state transitions on your app?

    ,n state transitions can be responded to state changes in anappropriate way by calling corresponding methods on app5sdelegate ob%ect.

    For e)ample= application;idBecome!ctive method can be usedto prepare to run as the foreground app.application;id3nterBac$ground method can be used to e)ecutesome code when app is running in the bac$ground and may be

    suspended at any time. applicationill3nterForeground methodcan be used to e)ecute some code when your app is moving outof the bac$ground applicationill1erminate method is calledwhen your app is being terminated.

    !3-Jist down appEs state transitions when it 'ets launched

    Before the launch of an app& it is said to be in not running state.hen an app is launched& it moves to the active or bac$ground

    state& after transitioning briefly through the inactive state.

    !4-Who calls the main function of you app durin' the applaunch cycle?

    ;uring app launching& the system creates a main thread for theapp and calls the app5s main function on that main thread. 1he code pro%ect5s default main function hands over control to theUIQit framewor$& which ta$es care of initialiing the app beforeit is run.

  • 8/9/2019 Objective C Questions

    13/37

    !!-What is the use of controller object )&5pplication?

    "ontroller ob%ect UI!pplication is used without subclassing tomanage the application event loop.It coordinates other high-

    level app behaviors. It wor$s along with the app delegate ob%ectwhich contains app-level logic.

    !$-Which object is create by )&5pplication@ain function at applaunch time?

    1he app delegate ob%ect is created by UI!pplication'ain function at app launch time. 1he app delegate ob%ect5s main %obis to handle state transitions within the app.

    !%- How is the app dele'ate is declared by Kcode projecttemplates?

     !pp delegate is declared as a subclass of UI+esponder by code pro%ect templates.

    !(-What happens if &5pplication object does not handle anevent?

    In such case the event will be dispatched to your app delegate for processing.

    !.- Which app specific objects store the appEs content?

    ;ata model ob%ects are app specific ob%ects and store app5scontent. !pps can also use document ob%ects to manage some orall of their data model ob%ects.

    $/-5re document objects reGuired for an application? What

    does they offer?

    ;ocument ob%ects are not re7uired but are very useful in grouping data that belongs in a single file or file pac$age.

    $1- Which object mana'e the presentation of appEs content onthe screen?

    View controller ob%ects ta$es care of the presentation of app5scontent on the screen. ! view controller is used to manage asingle view along with the collection of subviews. It ma$es its

  • 8/9/2019 Objective C Questions

    14/37

    views visible by installing them in the app5s window.

    $2- Which is the super class of all view controller objects?

    UIView"ontroller class. 1he functionality for loading views& presenting them& rotating them in response to device rotations&and several other standard system behaviors are provided byUIView"ontroller class.

    $3-What is the purpose of )&Window object?

    1he presentation of one or more views on a screen iscoordinated by UIindow ob%ect.

    $4-How do you chan'e the content of your app in order tochan'e the views displayed in the correspondin' window?

    1o change the content of your app& you use a view controller tochange the views displayed in the corresponding window.+emember& window itself is never replaced.

    $!-efine view object

    Views along with controls are used to provide visualrepresentation of the app content. View is an ob%ect that drawscontent in a designated rectangular area and it responds toevents within that area.

    $$-5part from incorporatin' views and controls< what else anapp can incorporate?

     !part from incorporating views and controls& an app can alsoincorporate "ore !nimation layers into its view and control

    hierarchies.

    $%- What are layer objects and what do they represent?

    #ayer ob%ects are data ob%ects which represent visual content. #ayerob%ects are used by views to render their content. "ustom layerob%ects can also be added to the interface to implement comple)animations and other types of sophisticated visual effects.

    $(-What is 5pp *undle?hen you build your i,S app& code pac$ages it as a bundle. !

  • 8/9/2019 Objective C Questions

    15/37

    $un!le is a directory in the file system that groups relatedresources together in one place. !n i,S app bundle contains theapp e)ecutable file and supporting resource files such as appicons& image files& and localied content.

    $.-efine property?

    It is used to access instance variables outside of class.

    %/-Why synthesi;ed is used? !fter declaring property we will have to tell compiler instantly byusing synthesie directive. 1his tells the compiler to generate setterand getter methods.

    %1-What is retainin'?It is reference count for an ob%ect.

    %2- What is webservice?1o get data in form of )ml &by using this we can get data from aserver.

    %3-What is parsin'?1o get data from web service we use parsing.

    %4-which #ml parser we use on iphone?*S'#J 4arser.

    %!-Which type of parse does iphone support?S!J parser.

    %$-+ame those classes used to establish connection bwapplication to webserver?(a*SU+# (b*SU+# +39U3S1 (c*SU+# ",**3"1I,*.

    %%-Lell the difference between O@ and ,5K Darser?(a;om is documents based parserJ.bS! is a event driven parser 

    %(-+ame three method of +,K@J parser(/did start element (Ldid end element (Rfound character.

    %.-Lell methods used in +,)=Jonnection(/"onnection did receive +esponse(L"onnection did recevice ;atat(R"onnection fail with error 

  • 8/9/2019 Objective C Questions

    16/37

    (K"onnection did finish loading.

    (/-What is json-parser? TS,*(Tava script ob%ect notationis a parser used to get data fromweb Server.

    (1-*y default which thin's are in the application?i4hone applications by default have R things/.main= entry point of application.L.!ppdelegate= perform basic application and functionality.R.indow= provide uiinterface.

    (2-Lell me about tab bar controller?It is used to display the data on the view.

    (3-Which are the protocols used in table view?1able view contain two delegate protocols(/ Uitable view data source(L.Uitable view delegate.ui view table view data source three method namely (/*o of sections.(L*o of rows in sections.(R"ell for row inde) path row.In ui table view delegate contain

    (/;id select row at inde) path row 

    (4-+ame data base used in iphone?(/S7l lite (L4list Rml (K"ore ;ata

    (!-Lell four frameworAs used in iphone?(/Ui $it framewor$(L'ap $it framewor$(R!;I $it framewor$(K"ore data framewor$

    (Mcore foundation framewor$

    ($-Lell me about sin'le inheritance in objective-c?,b%ective c subclass can derived from a single parent class.It is called single inheritanceJ.

    (%-Lell me about the @M architecture?'-model& V-view& "-controller 'ain advantage of 'V" architecture is to provide reusability andsecurityJ by separating the layer by using 'V" architecture.

     %o!el: it is a class model is interact with database.&ontroller: controller is used for by getting the data from model and 

  • 8/9/2019 Objective C Questions

    17/37

    controls the views.;isplay the information in views. = View 

    ((-What is the instance methods?Instance methods are essentially code routines that perform tas$s soinstances of clases we create methods to get and set the instancevariables and to display the current values of these variables.

    ;eclaration of instance method =: (voidclic$ me= (idsenderCVoid is return type which does not giving any thing here."lic$ me is method name.Id is data type which returns any type of ob%ect.

    (.-What is the class method?"lass methods wor$ at the class level and are common to all instanceof a class these methods are specific to the class overall as opposedto wor$ing on different instance data encapsulated in each classinstance.Ointerface class name =ns ob%ect 

     D(class name ?new alloc=-(inttotal open

    ./-What is data encapsulation?;ata is contained within ob%ects and is not accessible by any otherthan via methods defined on the class is called data encapsulation.

    .1-What is accessor methods? !ccessor methods are methods belonging to a class that allow to getand set the values of instance valuables contained within the class.

    .2-What is synthesi;ed accessor methods?,b%ective-c provides a mechanism that automates the creation ofaccessor methods that are called synthesied accessor methods thatare implemented through use of the Oproperty and Osynthesied.

    .3-How to access the encapsulated data in objective-c?(a;ata encapsulation encourages the use of methods to get and setthe values of instance variables in a class.(bBut the developer to want to directly access an instance variablewithout having to go through an accessor method.

    (c In ob%ective-c synta) for an instance variable is as follow Eclassinstance variable name 

  • 8/9/2019 Objective C Questions

    18/37

    .4-What is dot notation?;ot notation features introduced into version L.0 of ob%ective-c. ;otnotation involves accessing an instance variable by specifying a classinstanceJ followed by a dotJ followed in turn by the name ofinstance variable or property to be accessed..!-ifference between shallow copy and deep copy?Shallow copy is also $nown as address copy. In this process you onlycopy address not actual data while in deep copy you copy data.Suppose there are two ob%ects ! and B. ! is pointing to a differentarray while B is pointing to different array. *ow what I will do is

     following to do shallow copy."har ?! < a5&5b5&5c5DC"har ?B <)5&5y5&55DCB < !C*ow B is pointing is at same location where !

     pointer is pointing.Both ! and B in this case sharing same data. if

    change is made both will get altered value of data.!dvantage is thatcoping process is very fast and is independent of sie of array.

    while in deep copy data is also copied. 1his process is slow but Both !and B have their own copies and changes made to any copy& other willcopy will not be affected.

    .$-ifference between cate'ories and e#tensions?"lass e)tensions are similar to categories. 1he main difference is that

    with an e)tension& the compiler will e)pect you to implement themethods within your main Oimplementation& whereas with acategory you have a separate Oimplementation bloc$. So you should

     pretty much only use an e)tension at the top of your main .m file(the only place you should care about ivars& incidentally P it5s meantto be %ust that& an e)tension.

    .%-What are MO and M?'(&: *ormally instance variables are accessed through properties oraccessors but QV" gives another way to access variables in form of

    strings. In this way your class acts li$e a dictionary and your propertyname for e)ample ageJ becomes $ey and value that property holdsbecomes value for that $ey. For e)ample& you have employee classwith name property.You access property li$e

    *SString age < emp.ageC

    setting property value.

  • 8/9/2019 Objective C Questions

    19/37

    emp.age < OJL0WC

    *ow how QV" wor$s is li$e this

    Eemp valueForQey=OXageXC

    Eemp setValue=OXLMX forQey=OXageXC

    '() : 1he mechanism through which ob%ects are notified when thereis change in any of property is called QV,.

    For e)ample& person ob%ect is interested in getting notification whenaccountBalance property is changed in Ban$!ccount ob%ect.1o achievethis& 4erson ,b%ect must register as an observer of the Ban$!ccount5saccountBalance property by sending anadd,bserver=forQey4ath=options=conte)t= message.

    .(-an 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 tagsor you canalso chec$ them by comparing their memory addresses.

    ..-,wap the two variable values without taAin' third variable?int )

  • 8/9/2019 Objective C Questions

    20/37

    information for you. +e7uest is initiated by server not the device orclient.Nlow of push notificationYour web server sends message (device to$en payload to !pple

     push notification service (!4*S & then !4*S routes this message todevice whose device to$en specified in notification.

    1/1-What is polymorphism?1his is very famous 7uestion and every interviewer as$s this. Few

     people say polymorphism means multiple forms and they start givinge)ample of draw function which is right to some e)tent butinterviewer is loo$ing for more detailed answer.

     !bility of base class pointer to call function from derived class atruntime is called polymorphism.

    For e)ample& there is super class human and there are two subclassessoftware engineer and hardware engineer. *ow super class human canhold reference to any of subclass because software engineer is $ind of human. Suppose there is spea$ function in super class and everysubclass has also spea$ function. So at runtime& super class referenceis pointing to whatever subclass& spea$ function will be called of thatclass. I hope I am able to ma$e you understand.

    1/1-What is responder chain?Suppose you have a hierarchy of views such li$e there is superview !

    which have subview B and B has a subview ". *ow you touch on innermost view ". 1he system will send touch event to subview " forhandling this event. If " View does not want to handle this event& thisevent will be passed to its superview B (ne)t responder. If B alsodoes not want to handle this touch event it will pass on to superview

     !. !ll the view which can respond to touch events are calledresponder chain. ! view can also pass its events to uiviewcontroller. If view controller also does not want to respond to touch event& it is

     passed to application ob%ect which discards this event.

    1/2-an we use one tableview with two different datasources? Howyou will achieve this?Yes. e can conditionally bind tableviews with two different datasources.

    1/3-What is a protocol?

     ! protocol is a language feature in ob%ective " which providesmultiple inheritance in a single inheritance language. ,b%ective" supports two types of protocols=

    H !d hoc protocols called informal protocolH "ompiler protocols called formal protocols

  • 8/9/2019 Objective C Questions

    21/37

    You must create your own autorelease pool as soon as the thread begins e)ecutingC otherwise& your application will lea$ ob%ects

    1/4-Lhree occasions when you mi'ht use your own

    autorelease pools0

    /. If you are writing a program that is not based on a UI framewor$&such as a command-line tool.

    L. If you write a loop that creates many temporary ob%ects.You maycreate an autorelease pool inside the loop to dispose of those ob%ectsbefore the ne)t iteration. Using an autorelease pool in the loop helpsto reduce the ma)imum memory footprint of the application.

    R. If you spawn a secondary thread.

    1/!- &n5pp purchase product type

    /. &onsuma$le products must be purchased each time the user needsthat item. For e)ample& one-time services are commonlyimplemented as consumable products.

    L. Non-consuma$le products are purchased only once by a particularuser. ,nce a non-consumable product is purchased& it is provided toall devices associated with that user5s i1unes account. Store Qit

     provides built-in support to restore non-consumable products onmultiple devices.

    R.  Auto-rene*a$le su$scriptions are delivered to all of a user5s devices

    in the same way as non-consumable products. 8owever& auto-renewable subscriptions differ in other ways. hen you create anauto-renewable subscription in i1unes "onnect& you choose theduration of the subscription. 1he !pp Store automatically renews thesubscription each time its term e)pires. If the user chooses to notallow the subscription to be renewed& the user5s access to thesubscription is revo$ed after the subscription e)pires. Yourapplication is responsible for validating whether a subscription iscurrently active and can also receive an updated receipt for the mostrecent transaction.

    K. +ree su$scriptions are a way for you to put free subscription contentin *ewsstand. ,nce a user signs up for a free subscription& thecontent is available on all devices associated with the user5s !pple I;.Free subscriptions do not e)pire and can only be offered in*ewsstand-enabled apps

    1/$-the advanta'es and disadvanta'es about synchronousversus asynchronous connections

    1hat5s it& pretty fast and easy& but there are a lot of caveats =

    H 1he most important problem is that the thread which called

  • 8/9/2019 Objective C Questions

    22/37

    this method will be bloc$ed until the connection finish ortimeout& so we surely don5t want to start the connection on themain thread to avoid freeing the UI. 1hat means we need tocreate a new thread to handle the connection& and all

     programmers $now that threading is hard.

    H "ancellation& it5s not possible to cancel a synchronousconnection& which is bad because users li$e to have the choice tocancel an operation if they thin$ it ta$es too much time toe)ecute.

    H !uthentication& there is no way to deal with authenticationchallenges.

    H It5s impossible to parse data on the fly.

    So let5s put it up straight& avoid using synchronous*SU+#"onnection& there is absolutely no benefit of using it.

    It5s clear that as#nchronous connections give us more control =

    H You don5t have to create a new thread for the connectionbecause your main thread will not be bloc$ed.

    H You can easily cancel the connection %ust by calling the cancelmethod.

    H If you need authentication %ust implement the re7uireddelegate methods.

    H 4arsing data on the fly is easy.

    So clearly we have a lot of more control with this& and the code

    is really not difficult.

    3ven better& we don5t have to handle the creation of a newthread& which is a good thing& because you $now& threading ishard.

    ell& if you read me until here& you should be convinced to useasynchronous connections& and forget about synchronous ones.1hey clearly give us more control and possibilities and& in some

    case can spare us to create new thread.

  • 8/9/2019 Objective C Questions

    23/37

    So I encourage you to move away from synchronous connections& %ust thin$ of them as evil.

    1/%-What is the navi'ation controller?

    *avigation controller contains the stac$ of controllers everynavigation controllermust be having root view controller bydefault these controllers contain L method (a push view (b popviewBy default navigation controller contain table viewJ.

    1/(- What is the split view controller?

    1his control is used for ipad application and it contain propercontrollers by defaultsplit view controller contain root view

    controller and detail view controller.

    1/.-ocoa"ocoa is an application environment for both the 'ac ,S operatingsystem and i,S. It consists of a suite of ob%ect-oriented softwarelibraries& a runtime system& and an integrated developmentenvironment. "arbon is an alternative environment in 'ac ,S & butit is a compatibility framewor$ with procedural programmaticinterfaces intended to support e)isting 'ac ,S code bases.

    11/- NrameworAs that maAe ocoa !pp$it (!pplication QitFoundation

    111- Objective-,b%ective-" is a very dynamic language. Its dynamism frees a program

     from compile-time and lin$-time constraints and shifts much of theresponsibility for symbol resolution to runtime& when the user is incontrol. ,b%ective-" is more dynamic than other programminglanguages because its dynamism springs from three sources=;ynamic typingPdetermining the class of an ob%ect at runtime;ynamic bindingPdetermining the method to invo$e at runtime;ynamic loadingPadding new modules to a program at runtime

    112- Objective- vs [ 1he ,b%ective-" class allows a method and a variable with the e)actsame name. In "& they must be different.[ ,b%ective-" does not have a constructor or destructor. Instead it hasinit and dealloc methods& which must be called e)plicitly.

    [ ,b%ective-" uses and : to differentiate between factory andinstance methods& " uses static to specify a factory method.

  • 8/9/2019 Objective C Questions

    24/37

    [ 'ultiple inheritance is not allowed in ,b%-"& however we can use protocol to some e)tent.[ ,b%-" has runtime binding leading to dynamic lin$ing.[ ,b%-" has got categories.[ ,b%ective-" has a wor$-around for method overloading& but none

     for operator overloading.[ ,b%ective-" also does not allow stac$ based ob%ects. 3ach ob%ectmust be a pointer to a bloc$ of memory.[ In ,b%ective-" the message overloading is fa$ed by naming the

     parameters. " actually does the same thing but the compiler doesthe name mangling for us. In ,b%ective-"& we have to mangle thenames manually.[ ,ne of "5s advantages and disadvantages is automatic typecoercion.

    [ !nother feature " has that is missing in ,b%ective-" is references.Because pointers can be used wherever a reference is used& thereisn5t much need for references in general.[ 1emplates are another feature that " has that ,b%ective-"doesn5t. 1emplates are needed because " has strong typing andstatic binding that prevent generic classes& such as #ist and !rray.

    113-5ppilcation it5pp Ait1he !pplication Qit is a framewor$ containing all the ob%ects youneed to implement your graphical& event-driven user interface=

    windows& panels& buttons& menus& scrollers& and te)t fields. 1he !pplication Qit handles all the details for you as it efficiently drawson the screen& communicates with hardware devices and screenbuffers& clears areas of the screen before drawing& and clips views.You also have the choice at which level you use the !pplication Qit=[ Use Interface Builder to create connections from user interfaceob%ects to your application ob%ects.[ "ontrol the user interface programmatically& which re7uires more

     familiarity with !ppQit classes and protocols.[ Implement your own ob%ects by subclassing *SView or other classes.

    114-Noundation it1he Foundation framewor$ defines a base layer of ,b%ective-"classes. In addition to providing a set of useful primitive ob%ectclasses& it introduces several paradigms that define functionality notcovered by the ,b%ective-" language. 1he Foundation framewor$ isdesigned with these goals in mind=[ 4rovide a small set of basic utility classes.[ 'a$e software development easier by introducing consistentconventions for things such as deallocation.

    [ Support Unicode strings& ob%ect persistence& and ob%ect distribution.[ 4rovide a level of ,S independence& to enhance portability.

  • 8/9/2019 Objective C Questions

    25/37

    11!-ynamic and ,tatic Lypin'Static typed languages are those in which type chec$ing is done atcompile-time& whereas dynamic typed languages are those in whichtype chec$ing is done at run-time.,b%ective-" is a dynamically-typed language& meaning that you don5thave to tell the compiler what type of ob%ect you5re wor$ing with atcompile time. ;eclaring a type for a varible is merely a promisewhich can be bro$en at runtime if the code leaves room for such athing. You can declare your variables as type id& which is suitable forany ,b%ective-" ob%ect.

    11$-,electorsIn ,b%ective-"& selector has two meanings. It can be used to refer

    simply to the name of a method when it5s used in a source-codemessage to an ob%ect. It also& though& refers to the uni7ue identifierthat replaces the name when the source code is compiled. "ompiledselectors are of type S3#. !ll methods with the same name have thesame selector. You can use a selector to invo$e a method on an ob%ectPthis provides the basis for the implementation of the target-actiondesign pattern in "ocoa.Efriend performSelector=Oselector(gossip!bout=with,b%ect=a*eighborCis e7uivalent to=

    Efriend gossip!bout=a*eighborC

    11%-lass &ntrospection[ ;etermine whether an ob%ective-" ob%ect is an instance of a classEob% is'ember,f"lass=some"lassC[ ;etermine whether an ob%ective-" ob%ect is an instance of a class or its descendantsEob% isQind,f"lass=some"lassC[ 1he version of a classE'yString version 

    [ Find the class of an ,b%ective-" ob%ect"lass c < Eob%/ classC "lass c < E*SString classC[ Verify L ,b%ective-" ob%ects are of the same classEob%/ class

  • 8/9/2019 Objective C Questions

    26/37

    11.- Why cate'ory is better than inheritance?If category is used& you can use same class& no need to remember anew class-name. "ategory created on a base class is available on subclasses.

    12/-Normal Drotocols

    Formal 4rotocols allow us to define the interface for a set ofmethods& but implementation is not done. Formal 4rotocols areuseful when you are using ;istributed,b%ects& because they allow youto define a protocol for communication between ob%ects& so that the;, system doesn5t have to constantly chec$ whether or not a certainmethod is implemented by the distant ob%ect.

    121- Normal vs informal protocolIn addition to formal protocols& you can also define an informal

     protocol by grouping the methods in a category declaration=Ointerface *S,b%ect ('y4rotocol@@some'ethod(COend Informal protocols are typically declared as categories of the*S,b%ect class& because that broadly associates the method nameswith any class that inherits from *S,b%ect. Because all classes inherit

     from the root class& the methods aren5t restricted to any part of theinheritance hierarchy. (It is also possible to declare an informal

     protocol as a category of another class to limit it to a certain branchof the inheritance hierarchy& but there is little reason to do so.hen used to declare a protocol& a category interface doesn5t have acorresponding implementation. Instead& classes that implement the

     protocol declare the methods again in their own interface files anddefine them along with other methods in their implementation files.

     !n informal protocol bends the rules of category declarations to list a group of methods but not associate them with any particular class or

    implementation.Being informal& protocols declared in categories don5t receive muchlanguage support. 1here5s no type chec$ing at compile time nor achec$ at runtime to see whether an ob%ect conforms to the protocol.1o get these benefits& you must use a formal protocol. !n informal

     protocol may be useful when all the methods are optional& such as for a delegate& but (in 'ac ,S v/0.M and later it is typically betterto use a formal protocol with optional methods.

    122- Optional vs reGuired4rotocol methods can be mar$ed as optional using the Ooptional

  • 8/9/2019 Objective C Questions

    27/37

    $eyword. "orresponding to the Ooptional modal $eyword& there is aOre7uired $eyword to formally denote the semantics of the defaultbehavior. You can use Ooptional and Ore7uired to partition your

     protocol into sections as you see fit. If you do not specify any$eyword& the default is Ore7uired.Oprotocol 'y4rotocolOoptional-(void optional'ethodCOre7uired -(void re7uired'ethodCOend 

    123- @emory @ana'ementIf you alloc& retain& or copy@mutablecopy it& it5s your %ob to release

    it. ,therwise it isn5t.

    124-opy vs assi'n vs retain[ !ssign is for primitive values li$e B,,#& *SInteger or double. Forob%ects use retain or copy& depending on if you want to $eep areference to the original ob%ect or ma$e a copy of it.[ assign= In your setter method for the property& there is a simpleassignment of your instance variable to the new value& eg=(voidsetString=(*SString?newString string < newStringC

     D1his can cause problems since ,b%ective-" ob%ects use referencecounting& and therefore by not retaining the ob%ect& there is a chancethat the string could be deallocated whilst you are still using it.[ retain= this retains the new value in your setter method. Fore)ample=1his is safer& since you e)plicitly state that you want to maintain areference of the ob%ect& and you must release it before it will bedeallocated.(voidsetString=(*SString?newString 

    EnewString retainCEstring releaseCstring < newStringC

     D[ cop# = this ma$es a copy of the string in your setter method=1his is often used with strings& since ma$ing a copy of the originalob%ect ensures that it is not changed whilst you are using it.(voidsetString=(*SString?newString if(string2

  • 8/9/2019 Objective C Questions

    28/37

     D

    12!- alloc vs newallocJ creates a new memory location but doesn5t initialies it ascompared to newJ.

    12$- release vs pool drainreleaseJ frees a memory. drainJ releases the *S!utorelease4oolitself.

    12%- +,5uto=eleaseDool 0 release vs drainStrictly spea$ing& from the big picture perspective drain is note7uivalent to release=

    In a reference-counted environment& drain does perform the sameoperations as release& so the two are in that sense e7uivalent. 1oemphasise& this means you do not lea$ a pool if you use drain ratherthan release.In a garbage-collected environment& release is a no-op. 1hus it has noeffect. drain& on the other hand& contains a hint to the collector thatit should collect if neededJ. 1hus in a garbage-collectedenvironment& using drain helps the system balance collection sweeps.

    12(-autorelease vs release

     !utorelase= By sending an ob%ect an autorelease message& it is addedto the local !uto+elease4ool& and you no longer have to worry aboutit& because when the !uto+elease4ool is destroyed (as happens in thecourse of event processing by the system the ob%ect will receive arelease message& its +etain"ount will be decremented& and theAarbage"ollection system will destroy the ob%ect if the +etain"ountis ero.+elease= retain count is decremented at this point.

    12.- 5utorelease Dool

     !utorelease pools provide a mechanism whereby you can send anob%ect a deferredJ release message. 1his is useful in situationswhere you want to relin7uish ownership of an ob%ect& but want toavoid the possibility of it being deallocated immediately (such aswhen you return an ob%ect from a method. 1ypically& you don5t needto create your own autorelease pools& but there are some situationsin which either you must or it is beneficial to do so.

    13/- How autorelease pool is mana'ed3very time -autorelease is sent to an ob%ect& it is added to the inner-

    most autorelease pool. hen the pool is drained& it simply sends-release to all the ob%ects in the pool.

  • 8/9/2019 Objective C Questions

    29/37

     !utorelease pools are simply a convenience that allows you to defersending -release until laterJ. 1hat laterJ can happen in several

     places& but the most common in "ocoa AUI apps is at the end of thecurrent run loop cycle.

    131-@emory JeaAIf +etaining!nd+eleasing are not properly used then +etain"ount for

     !n,b%ect doesn5t reach 0. It doesn5t crash the application.

    132- "vent JoopIn a "ocoa application& user activities result in events. 1hese mightbe mouse clic$s or drags& typing on the $eyboard& choosing a menuitem& and so on. ,ther events can be generated automatically& fore)ample a timer firing periodically& or something coming in over the

    networ$. For each event& "ocoa e)pects there to be an ob%ect or group of ob%ects ready to handle that event appropriately. 1he eventloop is where such events are detected and routed off to theappropriate place. henever "ocoa is not doing anything else& it issitting in the event loop waiting for an event to arrive. (In fact&"ocoa doesn5t poll for events as suggested& but instead its mainthread goes to sleep. hen an event arrives& the ,S wa$es up thethread and event processing resumes. 1his is much more efficientthan polling and allows other applications to run more smoothly.3ach event is handled as an individual thing& then the event loop gets

    the ne)t event& and so on. If an event causes an update to bere7uired& this is chec$ed at the end of the event and if needed& andwindow refreshes are carried out.

    133-iffernce between bo#+ame and selfbo#+amebo)*ame= !ccessing directly.self. bo)*ame= !ccessing bo)*ame through accessors. If

     property@synthesie is not there it will throw error.

    134-What it does PCsynthesi;e bo#escription7bo#+ame:Q ?

    8ere you can use bo)*ame or self.bo)*ame. e cant usebo);escription.

    13!-ollectionIn "ocoa and "ocoa 1ouch& a collection is a Foundation framewor$class used for storing and managing groups of ob%ects. Its primaryrole is to store ob%ects in the form of either an array& a dictionary& or a set.

    13$-Lhreads and how to use

    Use this class when you want to have an ,b%ective-" method run inits own thread of e)ecution. 1hreads are especially useful when you

  • 8/9/2019 Objective C Questions

    30/37

    need to perform a lengthy tas$& but don5t want it to bloc$ thee)ecution of the rest of the application. In particular& you can usethreads to avoid bloc$ing the main thread of the application& whichhandles user interface and event-related actions. 1hreads can also beused to divide a large %ob into several smaller %obs& which can lead to

     performance increases on multi-core computers.1wo ways to create threads[ detach*ew1hreadSelector=to1arget=with,b%ect=[ "reate instances of *S1hread and start them at a later time usingthe startJ method.*S1hread is not as capable as Tava5s 1hread class& it lac$s[ Built-in communication system.[ !n e7uivalent of %oin(J

    13%-Lhreadsafehen it comes to threaded applications& nothing causes more fear orconfusion than the issue of handling signals. Signals are a low-levelBS; mechanism that can be used to deliver information to a processor manipulate it in some way. Some programs use signals to detectcertain events& such as the death of a child process. 1he system usessignals to terminate runaway processes and communicate other typesof information.1he problem with signals is not what they do& but their behaviorwhen your application has multiple threads. In a single-threaded

    application& all signal handlers run on the main thread. In amultithreaded application& signals that are not tied to a specifichardware error (such as an illegal instruction are delivered towhichever thread happens to be running at the time. If multiplethreads are running simultaneously& the signal is delivered towhichever one the system happens to pic$. In other words& signals canbe delivered to any thread of your application.1he first rule for implementing signal handlers in applications is toavoid assumptions about which thread is handling the signal. If aspecific thread wants to handle a given signal& you need to wor$ out

    some way of notifying that thread when the signal arrives. Youcannot %ust assume that installation of a signal handler from thatthread will result in the signal being delivered to the same thread.

    13(-+otification and Observers ! notification is a message sent to one or more observing ob%ects toinform them of an event in a program. 1he notification mechanism of "ocoa follows a $roa!cast model. It is a way for an ob%ect thatinitiates or handles a program event to communicate with anynumber of ob%ects that want to $now about that event. 1hese

    recipients of the notification& $nown as observers& can ad%ust theirown appearance& behavior& and state in response to the event. 1he

  • 8/9/2019 Objective C Questions

    31/37

    ob%ect sending (or posting the notification doesn5t have to $nowwhat those observers are. *otification is thus a powerful mechanism

     for attaining coordination and cohesion in a program. It reduces theneed for strong dependencies between ob%ects in a program (suchdependencies would reduce the reusability of those ob%ects. 'anyclasses of the Foundation& !ppQit& and other ,b%ective-" framewor$sdefine notifications that your program can register to observe.1he centerpiece of the notification mechanism is a per-processsingleton ob%ect $nown as the notification center( NSNoti,ication&enter . hen an ob%ect posts a notification& it goesto the notification center& which acts as a $ind of clearing house andbroadcast center for notifications. ,b%ects that need to $now aboutan event elsewhere in the application register with the notificationcenter to let it $now they want to be notified when that event

    happens. !lthough the notification center delivers a notification toits observers synchronously& you can post notifications asynchronously using a notification 7ueue (*S*otification9ueue.

    13.-ele'ate vs +otification[ 1he concept of notification differs from delegation in that it allowsa message to be sent to more than one ob%ect. It is more li$e abroadcast rather than a straight communication between twoob%ects. It removes dependencies between the sending and receivingob%ect(s by using a notification center to manage the sending and

    receiving of notifications. 1he sender does not need to $now if thereare any receivers registered with the notification center. 1here canbe one& many or even no receivers of the notification registered withthe notification center. Simply& ;elegate is /-to-/ ob%ect and*otification can be ?-to-? ob%ects.[ 1he other difference between notifications and delegates is thatthere is no possibility for the receiver of a notification to return avalue to the sender.[ 1ypical uses of notifications might be to allow different ob%ectswith an application to be informed of an event such as a file

    download completing or a user changing an application preference.1he receiver of the notification might then perform additionalactions such as processing the downloaded file or updating thedisplay.

    14/-Dlist4roperty lists organie data into named values and lists of valuesusing several ob%ect types. 1hese types give you the means to

     produce data that is meaningfully structured& transportable&storable& and accessible& but still as efficient as possible. 4roperty

    lists are fre7uently used by applications running on both 'ac ,S and i,S. 1he property-list programming interfaces for "ocoa and "ore

  • 8/9/2019 Objective C Questions

    32/37

    Foundation allow you to convert hierarchically structuredcombinations of these basic types of ob%ects to and from standard

     '#. You can save the '# data to dis$ and later use it to reconstructthe original ob%ects.1he user defaults system& which you programmatically access throughthe *SUser;efaults class& uses property lists to store ob%ectsrepresenting user preferences. 1his limitation would seem to e)cludemany $inds of ob%ects& such as *S"olor and *SFont ob%ects& from theuser default system. But if ob%ects conform to the *S"oding protocolthey can be archived to *S;ata ob%ects& which are property list:compatible ob%ects

    141-Helper Objects8elper ,b%ects are used throughout "ocoa and "ocoa1ouch& and

    usually ta$e the form of a delegate or dataSource. 1hey arecommonly used to add functionality to an e)isting class withouthaving to subclass it.

    142-luster lass"lass clusters are a design pattern that the Foundation framewor$ma$es e)tensive use of. "lass clusters group a number of privateconcrete subclasses under a public abstract superclass. 1he groupingof classes in this way simplifies the publicly visible architecture of anob%ect-oriented framewor$ without reducing its functional richness.

    143-ifferentiate Noundation vs ore Noundation"oreFoundation is a general-purpose " framewor$ whereasFoundation is a general-purpose ,b%ective-" framewor$. Both providecollection classes& run loops& etc& and many of the Foundation classesare wrappers around the "F e7uivalents. "F is mostly open-source &and Foundation is closed-source.&ore +oun!ation is the "-level !4I& which provides "FString&"F;ictionary and the li$e.+oun!ation is ,b%ective-"& which provides*SString& *S;ictionary& etc. "oreFoundation is written in " while

    Foundation is written in ,b%ective-". Foundation has a lot moreclasses "oreFoundation is the common base of Foundation and"arbon.

    144-ifference between coreata and atabase

    ata$ase &ore ata

    4rimary function is storing and fetching

    data

    4rimary function is graph management

    (although reading and writing to dis$ isimportant supporting feature

  • 8/9/2019 Objective C Questions

    33/37

    ,perates on data stored on dis$ (orminimally and incrementally loaded

    ,perates on ob%ects stored in memory(although they can be laily loaded fro

    Stores dumbJ data or$s with fully-fledged ob%ects that s

    manage a lot of their behavior and cansubclassed and customied for furtherbehaviors

    "an be transactional& thread-safe& multi-user 

    *on-transactional& single threaded& sinuser (unless you create an entire abstr around "ore ;ata which provides thesethings

    "an drop tables and edit data without

    loading into memory 

    ,nly operates in memory 

    4erpetually saved to dis$ (and often crashresilient

    +e7uires a save process

    "an be slow to create millions of new rows "an create millions of new ob%ects in-very 7uic$ly (although saving these ob%will be slow

    ,ffers data constraints li$e uni7ueJ $eys #eaves data constraints to the businessside of the program

    14!- ore data vs sGlite"ore data is an ob%ect graph management framewor$. It manages a

     potentially very large graph of ob%ect instances& allowing an app towor$ with a graph that would not entirely fit into memory by

     faulting ob%ects in and out of memory as necessary. "ore ;ata alsomanages constraints on properties and relationships and maintainsreference integrity (e.g. $eeping forward and bac$wards lin$s

    consistent when ob%ects are added@removed to@from a relationship."ore ;ata is thus an ideal framewor$ for building the modelJcomponent of an 'V" architecture.1o implement its graph management& "ore ;ata happens to use s7liteas a dis$ store. Itcould have been implemented using a differentrelational database or even a non-relational database such as"ouch;B. !s others have pointed out& "ore ;ata can also use '# or abinary format or a user-written atomic format as a bac$end (thoughthese options re7uire that the entire ob%ect graph fit into memory.

    14$-=etain cycle or =etain loophen ob%ect ! retains ob%ect B& and ob%ect B retains !. 1hen +etain

  • 8/9/2019 Objective C Questions

    34/37

    cycle happens. 1o overcome this use closeJ method.,b%ective-"5s garbage collector (when enabled can also deleteretain-loop groups but this is not relevant on the i4hone& where,b%ective-" garbage collection is not supported.

    14%-What is unnamed cate'ory ! named category P inter,ace +oo/+oo&ategor# P is generallyused to=i. 3)tend an e)isting class by adding functionality.ii. ;eclare a set of methods that might or might not be implementedby a delegate.

    Unnamed "ategories has fallen out of favor now that Oprotocol hasbeen e)tended to support Ooptional methods.

     ! class e)tension P inter,ace +oo/ P is designed to allow you todeclare additional private !4I P S4I or System 4rogramming InterfaceP that is used to implement the class innards. 1his typically appearsat the top of the .m file. !ny methods @ properties declared in theclass e)tension must be implemented in the Oimplementation& %ustli$e the methods@properties found in the public Ointerface."lass e)tensions can also be used to redeclare a publicly readonlyOproperty as readwrite prior to Osynthesie5ing the accessors.3)ample=+oo.h

    Ointerface Foo=*S,b%ectOproperty(readonly& copy *SString ?barC-(void publicSaucingCOend +oo.mOinterface Foo(Oproperty(readwrite& copy *SString ?barC: (void superSecretInternalSaucingCOend Oimplementation Foo

    Osynthesie barC. must implement the two methods or compiler will warn .Oend 

    14(-opy vs mutableopycopy always creates an immutable copy.mutable"opy always creates a mutable copy.

    14.- ,tron' vs WeaA1he strong and wea$ are new !+" types replacing retain and assign

    respectively.;elegates and outlets should be wea$.

  • 8/9/2019 Objective C Questions

    35/37

     ! strong re,erence is a reference to an ob%ect that stops it frombeing deallocated. In other words it creates a owner relationship.

     ! *ea re,erence is a reference to an ob%ect that does not stop it from being deallocated. In other words& it does not create an ownerrelationship.

    1!/-RRstron'< RRweaA< RRunsafeRunretained< RRautoreleasin'Aenerally spea$ing& these e)tra 7ualifiers don5t need to be used veryoften. You might first encounter these 7ualifiers and others whenusing the migration tool. For new pro%ects however& you generally youwon5t need them and will mostly use strong@wea$ with your declared

     properties. 11strong : is the default so you don5t need to type it. 1his means any ob%ect created using alloc@init is retained for the lifetime of its

    current scope. 1he current scopeJ usually means the braces in whichthe variable is declared  11*ea : means the ob%ect can be destroyed at anytime. 1his is onlyuseful if the ob%ect is somehow strongly referenced somewhere else.hen destroyed& a variable with \\wea$ is set to nil.

     11unsa,e1unretaine!  : is %ust li$e \\wea$ but the pointer is not setto nil when the ob%ect is deallocated. Instead the pointer is leftdangling.

     11autoreleasing& not to be confused with calling autorelease on anob%ect before returning it from a method& this is used for passing

    ob%ects by reference& for e)ample when passing *S3rror ob%ects byreference such as Emy,b%ect perform,perationith3rror=]tmpC

    1!1-Lypes of +,LableMiew"ell based and View based. In view based we can put multipleob%ects.

    1!2-5bstract class in cocoa

    "ocoa doesn5t provide anything called abstract. e can create a classabstract which gets chec$ only at runtime& compile time this is not

    chec$ed.Ointerface !bstract"lass = *S,b%ectOend Oimplementation !bstract"lass (idalloc if (self

  • 8/9/2019 Objective C Questions

    36/37

    [ 8114 stands for 8yper1e)t 1ransfer 4rotocol& whereas& 8114S is8yper1e)t 1ransfer 4rotocol Secure.[ 8114 transmits everything as plan te)t& while 8114S providesencrypted communication& so that only the recipient can decrypt andread the information. Basically& 8114S is a combination of 8114 andSS# (Secure Soc$ets #ayer. 1his SS# is that protocol which encryptsthe data.[ 8114 is fast and cheap& where 8114S is slow and e)pensive.

     !s& 8114S is safe it5s widely used during payment transactions or anysensitive transactions over the internet. ,n the other hand& 8114 isused most of the sites over the net& even this blogspot sites also use8114.[ 8114 U+#s starts with http=@@ and use port ^0 by default& while8114S U+#s stars with https=@@ and use port KKR.

    [ 8114 is unsafe from attac$s li$e man-in-the-middle andeavesdropping& but 8114S is secure from these sorts of attac$s.

    1!4-IArand "entral ;ispatch is not %ust a new abstraction around whatwe5ve already been using& it5s an entire new underlying mechanismthat ma$es multithreading easier and ma$es it easy to be asconcurrent as your code can be without worrying about the variablesli$e how much wor$ your "4U cores are doing& how many "4U cores

    you have and how much threads you should spawn in response. You %ust use the Arand "entral ;ispatch !4I5s and it handles the wor$ ofdoing the appropriate amount of wor$. 1his is also not %ust in "ocoa&anything running on 'ac ,S /0.N Snow #eopard can ta$e advantageof Arand "entral ;ispatch ( libdispatch because it5s included inlibSystem.dylib and all you need to do is include _import`[email protected] in your app and you5ll be able to ta$eadvantage of Arand "entral ;ispatch.

    1!!-How you attain the bacAward compatibility?

    1. Set the Base S;Q to "urrent version of 'ac (e). /0.2. Set the ;eployment S;Q to older version (e)./.K

    1!$-all *acASynchronous operations are ones that happen in step with your callingcode. 'ost of "ocoa wor$s this way= you send a message to an ob%ect&say to format a string& etc& and by the time that line of code isdoneJ& the operation is complete.But in the real world& some operations ta$e longer thaninstantaneousJ (some intensive graphics wor$& but mainly high orvariably latency things li$e dis$ I@, or worse& networ$ connectivity.

    1hese operations are unpredictable& and if the code were to bloc$until finish& it might bloc$ indefinitely or forever& and that5s no good.

    http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://adf.ly/1974254/http:/en.wikipedia.org/wiki/Man-in-the-middle_attackhttp://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://www.blogger.com/blogger.g?blogID=2378569646178591916http://adf.ly/1974254/http:/en.wikipedia.org/wiki/Man-in-the-middle_attack

  • 8/9/2019 Objective C Questions

    37/37

    So the way we handle this is to set up callbac$sJ: you say go offand do this operation& and when you5re done& call this other

     functionJ. 1hen inside that callbac$J function& you start the secondoperation that depends on the first. In this way& you5re not spinningin circles waiting& you %ust get called asynchronouslyJ when eachtas$ is done.