Upload
kieve
View
29
Download
1
Tags:
Embed Size (px)
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
Citation preview
OS X DevelopmentTom Schroeder
Table of Contents
Who cares?
History
Objective-C
Cocoa
Environment
Design
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
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)
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
Messages
Message is sent
Target and interpretation of message calculated runtime
Inspired by Smalltalk
Bracket Syntax
Interface and Implementation
Declaration and Definition
Interface - @interfaceInstance variablesPropertiesMethod declarationsInheritanceProtocol adoption
Implementation - @implementationDefinition of methods, properties, protocol conformity
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
Object Life Cycle
1 2 1 0
alloc retain release release
Retain-Release Process
Object Life Cycle - ARC
ARC: Automatic Reference CountingAutomatic memory managementCompiler inserts retains and releasesRestrictive but effective
Bridge castingC-style castvoid *
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 classesAdd methods to existing classes (even those in an imported framework)
ExtensionsAnonymous categoriesCommonly used to redeclare readonly property as readwrite
Dynamic Typing
id typePointer to Objective-C object
Message ForwardingHandle messageDrop messagePass it on
Blocks
Anonymous FunctionsSimilar to standard C functions
UsageEncapsulate 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 fasterObjective-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 FrameworksFoundation KitApplication KitCore Data
Other frameworks
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
Foundation ClassesContains over 100 different classes
NSObject - base classalloc, init, class
conformsToProtocol:
performSelector:onThread:withObject:waitUntilDone:
NSStringNSMutableString
NSArrayNSMutableArray
NSThread
NSDate
NSURL
AppKit
Contains objects required in creating a graphical application
WindowsButtonsScroll BoxesText Fields
ViewsNSView, NSTextView
ControllersNSViewController, 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 & VideoCore AudioCore VideoCore MIDI
Graphics/AnimationCore AnimationCore ImageOpenGLQuartz
BridgesRubyPython
NetworkingBonjourKerberos
Environment
Great environment Excellent development experience
Tools
Xcode
General IDE
Utilities
Apple LLVM Engine
Backend
Interface Builder
Graphical Interface Designer
Xcode
General IDECode EditorLLVM Engine IntegrationInterface Builder IntegrationProject Navigation
UtilitiesVersion EditorInstruments
Xcode
LLVM Engine
Compiler - ClangC/Objective-C/C++Syntax HighlightingCode CompletionLive Issues
Fix-itStatic Analysis
Improper memory allocationUnreachable codeImproper loops
llvm.org
Interface Builder
Integrated into Xcode
Design graphical interfaces for application
Drag and Drop
WYSIWYG
IBActions & IBOutletsConnect visual design to code
Interface Builder
Design
Objective-C and Cocoa utilize many design patterns and constructs
Provides stability and familiarity
Design PatternsModel-View-ControllerDelegationOthers…
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
Model-View-Controller
Smalltalk-80 MVC Paradigm
ParcPlace Systems, Inc.
Model-View-Controller
Controller
Model View
Action
UpdateNotify
Update
Observer
Mediator
Command
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
Design Patterns
Command patternNSInvocationUndo/redo
Observer patternKVO: Key-Value Observer
Adapter patternProtocols
Singleton PatternNSFileManagerNSApplication
MementoArchivingSerialization
ProxyNSProxy
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
Demo