Cocoa, Objective C Interview Questions – Part 1

Cocoa, Objective C Interview Questions – Part 1

Compiled By : Debasis Das (4-April-2015)

Will be publishing a series of cocoa, objective c interview questionsThe questions will range between basic to intermediate to advanced concepts. Below is the first in the series

1. What is Cocoa

  • Cocoa is an application environment and a suite of object oriented components to develop OSX and iOS Apps.
  • Cocoa apps are primarily developed using Objective C & Swift language.
  • Objective C is based out of ANSI C thus ANSI C code can be mixed with Objective C code while developing a Cocoa Application.
  • Cocoa Applications can also include C++ code.
  • Cocoa has 3 core frameworks
    1. Foundation Framework (Part of the core service layer)
    2. App Kit Framework (Application Frameworks)
    3. Core Data Framework.

2. What does Cocoa Offer?

  • Event Driven Behavior – Cocoa provides the infrastructure for event driven behavior.
  • It helps manage application, windows and workspaces
  • Has a rich library of user interface objects available in Interface builder. UI Objects can be dragged dropped from the interface builder or can be created from code. Some sample UI objects are (buttons, tables, views, windows, panels, drawers, segmented control etc).
  • Supports the following
    • Drawing and imaging
    • Interaction with file system and workspaces
    • Concurrency, multithreading , lazy loading etc
    • Internationalization
    • Different text representation
    • Maintains application preferences
    • Networking, communication with servers
    • Printing support, basic printing to advanced printing options such as pagination and content formatting
    • Handles Undo and Redo management
    • Audio and Video using Quicktime framework
    • Data exchange using Copy Paste and Drag Drop
    • Document based architecture (similar to word or excel)
    • Script-ability, i.e Applications responding to commands emitted from Apple Scripts (e.g: Play, Pause songs in iTunes using Apple Scripts)

3. What are the different Layers of the Mac OSX?

The Mac OSX is layered into the following

  • User Experience
    • Aqua
    • Dashboard
    • Spotlight
    • Accessibility
  •  Application Frameworks
    • Carbon
    • Java
    • Appkit
  • Graphics and Media (Application Services)
    • Core Animation
    • Core Image
    • Core Video
    • Quicktime
    • OpenGL
    • Quartz
    • Core Audio
  • Core Services
    • Carbon Core
    • Launch Services
    • Core Foundation
    • Foundation
  • Darwin

(Insert layer architecture here)

4. What are the main development Environment for Cocoa?

  • Xcode and Interface Builder (For UI Development using drag and drop from an object library)
  • Applications can also be built using a text editor and building the application from command line using makefiles and use the gdb debugger to debug the application from command line
  • Using Xcode and Interface builder it is very easy to design, manage, build and debug software products

5. What is Xcode?

  • Xcode is the engine that powers Apple’s integrated development environment (IDE) for OSX and iOS
  • Using Xcode developers can
    • Create and Manage Projects,
    • Specify platforms and targets, Dependencies and Build Configurations
    • Build the project
    • Debug the project
    • Can build code written in C, C++, Objective C
    • Create graphic user interface.
    • Manage Source Code using subversion & git

6. What are the compiling options in Xcode?

  • GCC – The GNC C Compiler (gcc)
  • LLVM – GCC (Low level virtual machine compiler). Provides past optimization times.
  • Clang – Fast compile times and diagnostics

7. What is Interface Builder?

  • Interface builder is a graphical tool for creating user interfaces
  • Has the following design elements
    • Nib Files /XIB files – contains the objects appearing on a user interface in an archived form
    • Object Library – Contains a list of UI Objects.
    • Inspector – Used for configuring the objects of a user interface
    • Connection Panel – connects outlets to actions.

8. What are the performance tools available for Cocoa Application Development?

  • Instruments – Instruments can be used to show the following
    • CPU Usage
    • Disk Reads and Writes
    • Memory Statistics
    • Thread activity
    • Network statistics etc
  • Shark – Traces function calls and graphs memory allocation
  • BigTop – Graphs performance trends
  • Spin Control – Gathers information about what the application was doing when the rainbow spinner appeared
  • Malloc Debug- Shows how much memory the application is consuming and which functions allocated large amounts of memory. Also helps find leaks by finding allocated memory that is not referenced anywhere in the program
  • QuartzDebug – helps debug applications that do large amounts of drawing and imaging

9. What are the primary Cocoa Frameworks required to build a Cocoa Application

  • There are two main frameworks required for building Cocoa Applications
    • Mac OSX  Cocoa Applications– AppKit Framework and Foundation Framework
    • iOS Apps – UIKit Framework and Foundation Framework

10. What is Foundation Framework, Specify some of its features

  • The Foundation framework defines a base layer of classes that can be used for any type of Cocoa program.
  • Foundation framework is designed for
    • Define basic object behavior and introduce consistent conventions for such things as memory management, object mutability, and notifications.
    • Supporting internationalization and localization with (among other things) bundle technology and Unicode strings.
    • For supporting object persistence.
    • For supporting object distribution.
    • Providing some measure of operating-system independence to support portability.
    • Providing object wrappers or equivalents for programmatic primitives, such as numeric values, strings, and collections. It also provides utility classes for accessing underlying system entities and services, such as ports, threads, and file systems.
  • The foundation class hierarchy is rooted at NSObject Class along with NSObject and NSCopying protocols
  • The Foundation Framework is logically grouped into Categories
    • Value Objects
      • Encapsulates values of primitive data types including strings, integers , floats, dates etc
      • NSNumber instantiates numbers that contains integers, floats, doubles
      • NSDate, NSTimeZone, NSCalendar, NSDateComponents provides objects that represent times, dates, calendar and locales
    • Collections
      • NSArray, NSDictionary, NSSet along with the mutable variants
    • Operation System Services
      • File System and URL NSFileManager. NSFileHandle, NSURL etc
      • Concurrency NSThread, NSOperation, NSOperationQueue
      • Interprocess Communication – NSPipe
      • Networking – NSNetService, NSNetServiceBrowser
    • Notifications
    • Archiving and Serialization
    • XML Processing – NSXML
    • Predicates and Expressions – NSPredicate, NSCompoundPredicate, NSComparisonPredicate
    • Spotlight Queries NSMetadataItem. NSMetadataQuery

11. What is AppKit Framework, Specify some of its features

  • AppKit framework is needed for implementing graphical, event -driven user interface in OSX like window, buttons, panels, menus, scroller, text field, table views etc.
  • The root of the AppKit framework is the NSResponder class
  • AppKit is divided primarily into these areas
    • User Interface Classes
      • Global Application Object – NSApplication
      • Windows and Views – NSWindow, NSView
      • Controller Classes – NSObjectController, NSArrayController, NSDictionaryController, NSTreeController
      • Panels (Dialogs) – NSPanel
      • Menus and Cursors – NSMenu, NSMenuItem, NSCursor
      • Grouping and ScrollViews – NSBox, NSScrollView, NSSplitView etc
      • Tables and Outline Views
    • Text and Fonts – NSFont, NSFontManager
    • Graphics and Colors – NSImage, NSColor, NSColorPanel. NSColorWell, NSGraphicsContext, NSBezierPath etc
    • Printing and Faxing (NSPrinter, NSPrintPanel, NSPageLayout, NSPrintInfo)
    • Document and File System Support NSFileWrapper, NSFileManager
    • Sharing Data with other applications – NSPasteBoard,
    • Drag & Drop
    • Spell Check – NSSpellServer

12. What is the basic difference between the Foundation and the AppKit Framework?

  • Foundation (Foundation.Framework)
    • Root Object
    • Classes representing basic data types such as strings and byte arrays.
    • Collection of classes for storing other Objects
    • Classes representing system information such as dates.
    • Classes representing Communication Ports
  • Application Kit (AppKit.Framework)
    • Graphical, event-driven user interface- Windows, panels, buttons, menus, scrollers, text fields etc.
    • Communication with hardware devices and screen buffers
    • Event handling, application and document management
    • Integrate and manage fonts, colors, printing etc

13. What are the root classes in Cocoa?

  • The root class does not inherit from any other class and all other classes inherit from the root class.
  • The root class primarily accesses and interacts with the objective C runtime
  • Cocoa has two root classes
    • NSObject
    • NSProxy (essential in the distributed object architecture)

14. State some of the important classes in Cocoa.

  • NSNumber – Can instantiate object that contains integers, floats or doubles
  • NSData – For storing streams of bytes, Writing data objects to the file system and reading from them
  • NSDate– Displaying dates, times in many formats. Time adjustments based on time zones
  • NSString – Different representation of character strings such as UTF-8 etc
  • NSAttributedString – Supports strings with attributes such as font etc
  • NSArray – Ordered collection of objects, uses zero based indexing
  • NSDictionary – Managing key value pairs, Dictionaries are unordered and must contain unique keys
  • NSSet – Similar to NSArray but unsorted. Contains distinct objects
  • NSFileManager – Used for file operations
  • NSThread – Used for creating multithreaded programs
  • NSOperation & NSOperationQueue – To perform multiple operations (concurrent & Non-Concurrent) in priority and dependence order
  • NSXMLParser – To process XML Data
  • NSXML – Used to represent a XML document as a hierarchial tree

15. What is Core Data?

  • Core Data is a cocoa framework that provides infrastructure for managing object graphs & persistent storage
  • Core Data saves model objects to a persistent store and fetches them
  • Central concept of Core Data is managed object. A managed object is a model object that is an instance of NSManagedObject
  • Managed Context – All managed objects must be registered in the managed object context. the context allows an application to add objects to the graph and remove them from it.

Cocoa, Objective C Interview Questions – Part 2


Posted in Cocoa, Objective C Tagged with: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

Hit Counter provided by technology news