350 likes | 430 Views
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.
E N D
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
History • 1985: Steve Jobs leaves Apple • Jobs founds NeXT • Mission: Create powerful computers for universities • NeXTSTEP • Object-Oriented, Multitasking Operating System • Interesting Note • Tim Berners-Lee designed and built first web browser on NeXTSTEP • 1996: NeXT purchased by Apple • NeXTSTEP becomes Mac OS X • 2001: Cheetah (10.0) • 2012: Mountain Lion (10.8)
Objective-C • Object-oriented language • ANSI C language (strict superset) • Smalltalk-inspired extension • Developed in early 80s • Stepstone (Brad Cox and Tom Love) • Goal: facilitate reusability and backwards compatible to C • Features & Constructs • Messages • Interfaces and Implementation • Properties • Object Life Cycle • ARC • Protocols • Categories • Dynamic Typing
Messages • Message is sent • Target and interpretation of message calculated runtime • Inspired by Smalltalk • Bracket Syntax
Interface and Implementation • Declaration and Definition • Interface - @interface • Instance variables • Properties • Method declarations • Inheritance • Protocol adoption • Implementation - @implementation • Definition of methods, properties, protocol conformity
Properties • Simple way to declare accessor methods • Encapsulation • Methods are generated by compiler - @synthesize • Allow use of “dot syntax” • Declaration contains attributes • Writability (readonly, readwrite) • Setter semantics (strong, weak, copy, assign, retain) • Atomicity
Object Life Cycle 1 2 1 0 alloc retain release release Retain-Release Process
Object Life Cycle - ARC • ARC: Automatic Reference Counting • Automatic memory management • Compiler inserts retains and releases • Restrictive but effective • Bridge casting • C-style cast • void *
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;
Categories • Open classes • Add methods to existing classes (even those in an imported framework) • Extensions • Anonymous categories • Commonly used to redeclarereadonly property as readwrite
Dynamic Typing • id type • Pointer to Objective-C object • Message Forwarding • Handle message • Drop message • Pass it on
Blocks • Anonymous Functions • Similar to standard C functions • Usage • Encapsulate code groups to execute concurrently • Dispatch • Execute on items in a collection • Fast enumeration • Easily parameterized
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 faster • Objective-C’s runtime is more complex (dynamic typing & message passing) • Objective-C is dynamically typed • Objective-C has built-in synchronization • @synchronize
Cocoa • Framework that provides applications the distinctive look and feel often associated with OS X • Underlying Frameworks • Foundation Kit • Application Kit • Core Data • Other frameworks
Foundation • Collection of base layer classes • Applications can be created solely with Foundation • Command line tools • Functionalities • General object behavior and life cycle • NSObject – base class • Localization • Portability • Wrappers • Primitives • Operating system level functionality • Ports • File I/O • Threads
Foundation Classes • Contains over 100 different classes • NSObject- base class • alloc, init, class • conformsToProtocol: • performSelector:onThread:withObject:waitUntilDone: • NSString • NSMutableString • NSArray • NSMutableArray • NSThread • NSDate • NSURL
AppKit • Contains objects required in creating a graphical application • Windows • Buttons • Scroll Boxes • Text Fields • Views • NSView, NSTextView • Controllers • NSViewController, NSWindowController
Core Data • Provides means to manage the data of an application • Data model • Serialization • XML • Binary • SQLite • Persistence • Managed Objects • Command Pattern • Undo/Redo
Other Frameworks • Audio & Video • Core Audio • Core Video • Core MIDI • Graphics/Animation • Core Animation • Core Image • OpenGL • Quartz • Bridges • Ruby • Python • Networking • Bonjour • Kerberos
Environment • Great environment Excellent development experience • Tools • Xcode • General IDE • Utilities • Apple LLVM Engine • Backend • Interface Builder • Graphical Interface Designer
Xcode • General IDE • Code Editor • LLVM Engine Integration • Interface Builder Integration • Project Navigation • Utilities • Version Editor • Instruments
LLVM Engine • Compiler - Clang • C/Objective-C/C++ • Syntax Highlighting • Code Completion • Live Issues • Fix-it • Static Analysis • Improper memory allocation • Unreachable code • Improper loops llvm.org
Interface Builder • Integrated into Xcode • Design graphical interfaces for application • Drag and Drop • WYSIWYG • IBActions & IBOutlets • Connect visual design to code
Design • Objective-C and Cocoa utilize many design patterns and constructs • Provides stability and familiarity • Design Patterns • Model-View-Controller • Delegation • Others…
Model-View-Controller • Divides system into three components • Model • Domain-specific data and operations • Platform-independent • View • Responsible for graphically displaying the model • Controller • Mediator for the model and view • Handles interactions with the system
Model-View-Controller ParcPlaceSystems, Inc. Smalltalk-80 MVC Paradigm
Model-View-Controller Mediator Controller Update Action Model View Notify Update Observer Command
Delegation • One class delegates action to another (helper object) • Inversion of control • Delegate & Delegator • Pass notifications • No polling • Utilizes protocols • Delegate conforms to methods for which delegator is aware
Design Patterns • Command pattern • NSInvocation • Undo/redo • Observer pattern • KVO: Key-Value Observer • Adapter pattern • Protocols • Singleton Pattern • NSFileManager • NSApplication • Memento • Archiving • Serialization • Proxy • NSProxy
Design Patterns • Composite • View Hierarchy • Decorator • Categories • Façade • NSImage • Bitmap (jpg, png) • Vector (pdf) • Iterator • Fast enumeration • Mediator • Controller classes • Abstract Factory • Class Clusters • NSString • NSArray • Chain of Responsibility • NSResponder • AppKit Responder Chain