Vous êtes sur la page 1sur 6

Difference between cocoa and cocoa touch

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
same functionality 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.
You will come to know more of the nuances between the two and
will soon be able to instinctively know what will work on an iPhone
with little/no modification and what will require some work to port
between, but it's not that difficult.
Where can you test Apple iPhone apps if you dont have the device?
A.iOSSimulatorcanbeusedtotestmobileapplications.XcodetoolthatcomesalongwithiOSSDK
includesXcodeIDEaswellastheiOSSimulator.Xcodealsoincludesallrequiredtoolsand
frameworksforbuildingiOSapps.However,itisstronglyrecommendedtotesttheapponthereal
devicebeforepublishingit.
Q2.DoesiOSsupportmultitasking?
A.iOS4andabovesupportsmultitaskingandallowsappstoremaininthebackgrounduntiltheyare
launchedagainoruntiltheyareterminated.
Q3.WhichJSONframeworkissupportedbyiOS?
A.SBJsonframeworkissupportedbyiOS.ItisaJSONparserandgeneratorforObjectiveC.SBJson
providesflexibleAPIsandadditionalcontrolthatmakesJSONhandlingeasier.
Q4.WhatarethetoolsrequiredtodevelopiOSapplications?
A.iOSdevelopmentrequiresIntelbasedMacintoshcomputerandiOSSDK.
Q5.NametheframeworkthatisusedtoconstructapplicationsuserinterfaceforiOS.
A.TheUIKitframeworkisusedtodevelopapplicationsuserinterfaceforiOS.UIKit
frameworkprovideseventhandling,drawingmodel,windows,views,andcontrolsspecifically
designedforatouchscreeninterface.
Q6.NametheapplicationthreadfromwhereUIKitclassesshouldbeused?
A.UIKitclassesshouldbeusedonlyfromanapplicationsmainthread.Note:Thederivedclassesof
UIResponderandtheclasseswhichmanipulateapplicationsuserinterfaceshouldbeusedfrom
applicationsmainthread.
Q7.WhichAPIisusedtowritetestscriptsthathelpinexercisingtheapplication'suserinterface
elements?
A.UIAutomationAPIisusedtoautomatetestprocedures.TestsscriptsarewritteninJavaScripttothe
UIAutomationAPI.Thisinturnsimulatesuserinteractionwiththeapplicationandreturnslog
informationtothehostcomputer.

AppStatesandMultitasking

Q8.WhyanapponiOSdevicebehavesdifferentlywhenrunninginforegroundthanin
background?
A.Anapplicationbehavesdifferentlywhenrunninginforegroundthaninbackgroundbecauseofthe
limitationofresourcesoniOSdevices.
Q9.Howcananoperatingsystemimprovebatterylifewhilerunninganapp?
A.Anappisnotifiedwhenevertheoperatingsystemmovestheappsbetweenforegroundand
background.Theoperatingsystemimprovesbatterylifewhileitboundswhatyourappcandointhe
background.Thisalsoimprovestheuserexperiencewithforegroundapp.
Q10.Whichframeworkdeliverseventtocustomobjectwhenappisinforeground?
A.TheUIKitinfrastructuretakescareofdeliveringeventstocustomobjects.Asanappdeveloper,you
havetooverridemethodsintheappropriateobjectstoprocessthoseevents.

AppStates
Q11.Whenanappissaidtobeinnotrunningstate?
A.Anappissaidtobein'notrunning'statewhen:
itisnotlaunched.
itgetsterminatedbythesystemduringrunning.
Q12.Assumethatyourappisrunningintheforegroundbutiscurrentlynotreceivingevents.In
whichsateitwouldbein?
A.AnappwillbeinInActivestateifitisrunningintheforegroundbutiscurrentlynotreceiving
events.AnappstaysinInActivestateonlybrieflyasittransitionstoadifferentstate.
Q13.GiveexamplescenarioswhenanapplicationgoesintoInActivestate?
A.AnappcangetintoInActivestatewhentheuserlocksthescreenorthesystempromptstheuserto
respondtosomeevente.g.SMSmessage,incomingcalletc.
Q14.Whenanappissaidtobeinactivestate?
A.Anappissaidtobeinactivestatewhenitisrunninginforegroundandisreceivingevents.
Q15.Nametheappsatewhichitreachesbrieflyonitswaytobeingsuspended.
A.Anappentersbackgroundstatebrieflyonitswaytobeingsuspended.
Q16.Assumethatanappisnotinforegroundbutisstillexecutingcode.Inwhichstatewillitbe
in?
A.Backgroundstate.
Q17.Anappisloadedintomemorybutisnotexecutinganycode.Inwhichstatewillitbein?
A.Anappissaidtobeinsuspendedstatewhenitisstillinmemorybutisnotexecutinganycode.
Q18.Assumethatsystemisrunninglowonmemory.Whatcansystemdoforsuspendedapps?
A.Incasesystemisrunninglowonmemory,thesystemmaypurgesuspendedappswithoutnotice.
Q19.Howcanyourespondtostatetransitionsonyourapp?
A.Onstatetransitionscanberespondedtostatechangesinanappropriatewayby
callingcorrespondingmethodsonapp'sdelegateobject.
Forexample:
applicationDidBecomeActivemethodcanbeusedtopreparetorunastheforegroundapp.
applicationDidEnterBackgroundmethodcanbeusedtoexecutesomecodewhenappisrunninginthe
backgroundandmaybesuspendedatanytime.
applicationWillEnterForegroundmethodcanbeusedtoexecutesomecodewhenyourappismoving
outofthebackground
applicationWillTerminatemethodiscalledwhenyourappisbeingterminated.
Q20.Listdownapp'sstatetransitionswhenitgetslaunched.
A.Beforethelaunchofanapp,itissaidtobeinnotrunningstate.
Whenanappislaunched,itmovestotheactiveorbackgroundstate,aftertransitioningbrieflythrough
theinactivestate.
Q21.Whocallsthemainfunctionofyouappduringtheapplaunchcycle?
A.Duringapplaunching,thesystemcreatesamainthreadfortheappandcallstheappsmainfunction
onthatmainthread.TheXcodeproject'sdefaultmainfunctionhandsovercontroltotheUIKit
framework,whichtakescareofinitializingtheappbeforeitisrun.

CoreAppObjects
Q22.WhatistheuseofcontrollerobjectUIApplication?
A.ControllerobjectUIApplicationisusedwithoutsubclassingtomanagetheapplicationeventloop.

Itcoordinatesotherhighlevelappbehaviors.
Itworksalongwiththeappdelegateobjectwhichcontainsapplevellogic.
Q23.WhichobjectiscreatebyUIApplicationMainfunctionatapplaunchtime?
A.TheappdelegateobjectiscreatedbyUIApplicationMainfunctionatapplaunchtime.Theapp
delegateobject'smainjobistohandlestatetransitionswithintheapp.
Q24.HowistheappdelegateisdeclaredbyXcodeprojecttemplates?
A.AppdelegateisdeclaredasasubclassofUIResponderbyXcodeprojecttemplates.
Q25.WhathappensifIApplicationobjectdoesnothandleanevent?
A.Insuchcasetheeventwillbedispatchedtoyourappdelegateforprocessing.
Q26.Whichappspecificobjectsstoretheapp'scontent?
A.Datamodelobjectsareappspecificobjectsandstoreappscontent.Appscanalsousedocument
objectstomanagesomeoralloftheirdatamodelobjects.
Q27.Aredocumentobjectsrequiredforanapplication?Whatdoestheyoffer?
A.Documentobjectsarenotrequiredbutareveryusefulingroupingdatathatbelongsinasinglefile
orfilepackage.
Q28.Whichobjectmanagethepresentationofapp'scontentonthescreen?
A.Viewcontrollerobjectstakescareofthepresentationofapp'scontentonthescreen.Aview
controllerisusedtomanageasingleviewalongwiththecollectionofsubviews.Itmakesitsviews
visiblebyinstallingthemintheappswindow.
Q29.Whichisthesuperclassofallviewcontrollerobjects?
A.UIViewControllerclass.Thefunctionalityforloadingviews,presentingthem,rotatingthemin
responsetodevicerotations,andseveralotherstandardsystembehaviorsareprovidedby
UIViewControllerclass.
Q30.WhatisthepurposeofUIWindowobject?
A.ThepresentationofoneormoreviewsonascreeniscoordinatedbyUIWindowobject.
Q31.Howdoyouchangethecontentofyourappinordertochangetheviewsdisplayedinthe
correspondingwindow?
A.Tochangethecontentofyourapp,youuseaviewcontrollertochangetheviewsdisplayedinthe
correspondingwindow.Remember,windowitselfisneverreplaced.
Q32.Defineviewobject.
A.Viewsalongwithcontrolsareusedtoprovidevisualrepresentationoftheappcontent.Viewisan
objectthatdrawscontentinadesignatedrectangularareaanditrespondstoeventswithinthatarea.
Q33.Youwishtodefineyourcustomview.Whichclasswillbesubclassed?
A.CustomviewscanbedefinedbysubclassingUIView.
Q34.Apartfromincorporatingviewsandcontrols,whatelseanappcanincorporate?
A.Apartfromincorporatingviewsandcontrols,anappcanalsoincorporateCoreAnimationlayers
intoitsviewandcontrolhierarchies.
Q35.Whatarelayerobjectsandwhatdotheyrepresent?
A.Layerobjectsaredataobjectswhichrepresentvisualcontent.Layerobjectsareusedbyviewsto
rendertheircontent.Customlayerobjectscanalsobeaddedtotheinterfacetoimplementcomplex
animationsandothertypesofsophisticatedvisualeffects.

BEGINNER

Q: How would you create your own custom view?


A: Subclass the UIView class.

Q: 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 reduces
message send overhead and increases pipelining potential.)

Q: 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.

Q: Whats the difference between a NSArray and a


NSMutableArray?
A: A NSArrays contents can not be modified once its been
created whereas a NSMutableArray can be modified as
needed, i.e items can be added/removed from it.

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 objects retain count is reduced to 0, it is
deallocated.

Q: 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).

Q: Is a delegate retained?
A: No, the delegate is never retained! Ever!

INTERMEDIATE

Q: 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 from
the run loop and perform the selector.

Q: 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 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 tasks memory footprint
increasing unnecessarily. You can also consider creating pools
with a narrower scope or use NSOperationQueue with its own
autorelease pool. (Also important You only release or
autorelease objects you own.)

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

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.

Q: 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.

ADVANCED

Q: Is the delegate for a CAAnimation retained?


A: Yes it is!! This is one of the rare exceptions to memory
management rules.

Q: What happens when the following code executes?


1

Ball *ball = [[[[Ball alloc] init] autorelease]


autorelease];

A: It will crash because its added twice to the autorelease


pool and when it it dequeued the autorelease pool calls
release more than once.

Q: 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

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.

Vous aimerez peut-être aussi