Top 15 Cocoa Api Interview Questions You Must Prepare 19.Mar.2024

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 Scroll Views – 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.

  • 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 make files 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.

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

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

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.

Big Top: 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.

Quartz Debug: helps debug applications that do large amounts of drawing and imaging.

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++, and Objective C
  • Create graphic user interface.
  • Manage Source Code using subversion & git.

Interface builder is a graphical tool for creating user interfaces.

Has the following design element:

  • Nib Files /XIB files:contains the objects appearing on a user interface in an archived form.
  • Objects Library: Contains a list of UI Objects.
  • Inspector: Used for configuring the objects of a user interface.
  • Connection Panel: connects outlets to actions.

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.

NSNumber: Can instantiate object that contains integers, floats or doubles.

NSDate: 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 hierarchical tree.

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.

The Mac OSX is layered into the following:

User Experience:

  • Aqua
  • Dashboard
  • Spotlight
  • Accessibility

Application Frameworks:

  • Carbon
  • Java
  • Applet

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

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.

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)

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

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