OS X Development

35
OS X Development Tom Schroeder

description

OS X Development. Tom Schroeder. Table of Contents. Who cares? History Objective-C Cocoa Environment Design. Who cares?. Objective- C TIOBE: Language of the Year - 2011 Currently ranked #3 Mac and OS X market share continues to rise Flourishing App Store OS X and iOS apps numerous. - PowerPoint PPT Presentation

Transcript of OS X Development

Page 1: OS X Development

OS X DevelopmentTom Schroeder

Page 2: OS X Development

Table of Contents

Who cares?

History

Objective-C

Cocoa

Environment

Design

Page 3: OS X Development

Who cares?

Objective-CTIOBE: Language of the Year - 2011

Currently ranked #3

Mac and OS X market share continues to rise

Flourishing App StoreOS X and iOS apps numerous

Page 4: OS X Development

History1985: Steve Jobs leaves Apple

Jobs founds NeXTMission: Create powerful computers for universities

NeXTSTEPObject-Oriented, Multitasking Operating System

Interesting NoteTim Berners-Lee designed and built first web browser on NeXTSTEP

1996: NeXT purchased by Apple

NeXTSTEP becomes Mac OS X2001: Cheetah (10.0)

2012: Mountain Lion (10.8)

Page 5: OS X Development

Objective-C

Object-oriented language

ANSI C language (strict superset)

Smalltalk-inspired extension

Developed in early 80sStepstone (Brad Cox and Tom Love)

Goal: facilitate reusability and backwards compatible to C

Features & Constructs

Messages

Interfaces and Implementation

PropertiesObject Life Cycle

ARCProtocols

CategoriesDynamic Typing

Page 6: OS X Development

Messages

Message is sent

Target and interpretation of message calculated runtime

Inspired by Smalltalk

Bracket Syntax

Page 7: OS X Development

Interface and Implementation

Declaration and Definition

Interface - @interfaceInstance variablesPropertiesMethod declarationsInheritanceProtocol adoption

Implementation - @implementationDefinition of methods, properties, protocol conformity

Page 8: OS X Development

PropertiesSimple way to declare accessor methods

EncapsulationMethods are generated by compiler - @synthesize

Allow use of “dot syntax”

Declaration contains attributesWritability (readonly, readwrite) Setter semantics (strong, weak, copy, assign, retain)Atomicity

Page 9: OS X Development

Object Life Cycle

1 2 1 0

alloc retain release release

Retain-Release Process

Page 10: OS X Development

Object Life Cycle - ARC

ARC: Automatic Reference CountingAutomatic memory managementCompiler inserts retains and releasesRestrictive but effective

Bridge castingC-style castvoid *

Page 11: OS X Development

Protocols

Declare methods to be implemented by a class

Adoption and Conformity

Similar to “interface” in Java

Objects can be referred to by the adopted protocol

id <NSTabViewDelegate> delegate;

Page 12: OS X Development

Categories

Open classesAdd methods to existing classes (even those in an imported framework)

ExtensionsAnonymous categoriesCommonly used to redeclare readonly property as readwrite

Page 13: OS X Development

Dynamic Typing

id typePointer to Objective-C object

Message ForwardingHandle messageDrop messagePass it on

Page 14: OS X Development

Blocks

Anonymous FunctionsSimilar to standard C functions

UsageEncapsulate code groups to execute concurrently

Dispatch

Execute on items in a collection

Fast enumeration

Easily parameterized

Page 15: OS X Development

Comparison to C++

Objective-C is true superset of C (simple - small addition)

C++ is complex - adds features such as templates, operator overloading, etc.

C++ is generally fasterObjective-C’s runtime is more complex (dynamic typing & message passing)

Objective-C is dynamically typed

Objective-C has built-in synchronization@synchronize

Page 16: OS X Development

Cocoa

Framework that provides applications the distinctive look and feel often associated with OS X

Underlying FrameworksFoundation KitApplication KitCore Data

Other frameworks

Page 17: OS X Development

FoundationCollection of base layer classes

Applications can be created solely with FoundationCommand line tools

FunctionalitiesGeneral object behavior and life cycle

NSObject – base class

Localization

Portability

WrappersPrimitives

Operating system level functionality

Ports

File I/O

Threads

Page 18: OS X Development

Foundation ClassesContains over 100 different classes

NSObject - base classalloc, init, class

conformsToProtocol:

performSelector:onThread:withObject:waitUntilDone:

NSStringNSMutableString

NSArrayNSMutableArray

NSThread

NSDate

NSURL

Page 19: OS X Development

AppKit

Contains objects required in creating a graphical application

WindowsButtonsScroll BoxesText Fields

ViewsNSView, NSTextView

ControllersNSViewController, NSWindowController

Page 20: OS X Development

Core Data

Provides means to manage the data of an application

Data model

Serialization

XML

Binary

SQLite

Persistence

Managed Objects

Command Pattern

Undo/Redo

Page 21: OS X Development

Other Frameworks

Audio & VideoCore AudioCore VideoCore MIDI

Graphics/AnimationCore AnimationCore ImageOpenGLQuartz

BridgesRubyPython

NetworkingBonjourKerberos

Page 22: OS X Development

Environment

Great environment Excellent development experience

Tools

Xcode

General IDE

Utilities

Apple LLVM Engine

Backend

Interface Builder

Graphical Interface Designer

Page 23: OS X Development

Xcode

General IDECode EditorLLVM Engine IntegrationInterface Builder IntegrationProject Navigation

UtilitiesVersion EditorInstruments

Page 24: OS X Development

Xcode

Page 25: OS X Development

LLVM Engine

Compiler - ClangC/Objective-C/C++Syntax HighlightingCode CompletionLive Issues

Fix-itStatic Analysis

Improper memory allocationUnreachable codeImproper loops

llvm.org

Page 26: OS X Development

Interface Builder

Integrated into Xcode

Design graphical interfaces for application

Drag and Drop

WYSIWYG

IBActions & IBOutletsConnect visual design to code

Page 27: OS X Development

Interface Builder

Page 28: OS X Development

Design

Objective-C and Cocoa utilize many design patterns and constructs

Provides stability and familiarity

Design PatternsModel-View-ControllerDelegationOthers…

Page 29: OS X Development

Model-View-Controller

Divides system into three componentsModel

Domain-specific data and operationsPlatform-independent

ViewResponsible for graphically displaying the model

ControllerMediator for the model and viewHandles interactions with the system

Page 30: OS X Development

Model-View-Controller

Smalltalk-80 MVC Paradigm

ParcPlace Systems, Inc.

Page 31: OS X Development

Model-View-Controller

Controller

Model View

Action

UpdateNotify

Update

Observer

Mediator

Command

Page 32: OS X Development

Delegation

One class delegates action to another (helper object)

Inversion of controlDelegate & Delegator

Pass notificationsNo polling

Utilizes protocolsDelegate conforms to methods for which delegator is aware

Page 33: OS X Development

Design Patterns

Command patternNSInvocationUndo/redo

Observer patternKVO: Key-Value Observer

Adapter patternProtocols

Singleton PatternNSFileManagerNSApplication

MementoArchivingSerialization

ProxyNSProxy

Page 34: OS X Development

Design Patterns

CompositeView Hierarchy

DecoratorCategories

FaçadeNSImage

Bitmap (jpg, png)

Vector (pdf)

IteratorFast enumeration

Mediator

Controller classes

Abstract Factory

Class Clusters

NSString

NSArray

Chain of Responsibility

NSResponder

AppKit Responder Chain

Page 35: OS X Development

Demo