os x development
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 PresentationTRANSCRIPT
![Page 1: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/1.jpg)
OS X DevelopmentTom Schroeder
![Page 2: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/2.jpg)
Table of Contents
Who cares?
History
Objective-C
Cocoa
Environment
Design
![Page 3: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/3.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/4.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/5.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/6.jpg)
Messages
Message is sent
Target and interpretation of message calculated runtime
Inspired by Smalltalk
Bracket Syntax
![Page 7: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/7.jpg)
Interface and Implementation
Declaration and Definition
Interface - @interfaceInstance variablesPropertiesMethod declarationsInheritanceProtocol adoption
Implementation - @implementationDefinition of methods, properties, protocol conformity
![Page 8: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/8.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/9.jpg)
Object Life Cycle
1 2 1 0
alloc retain release release
Retain-Release Process
![Page 10: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/10.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/12.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/13.jpg)
Dynamic Typing
id typePointer to Objective-C object
Message ForwardingHandle messageDrop messagePass it on
![Page 14: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/14.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/15.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/16.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/17.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/18.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/19.jpg)
AppKit
Contains objects required in creating a graphical application
WindowsButtonsScroll BoxesText Fields
ViewsNSView, NSTextView
ControllersNSViewController, NSWindowController
![Page 20: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/20.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/21.jpg)
Other Frameworks
Audio & VideoCore AudioCore VideoCore MIDI
Graphics/AnimationCore AnimationCore ImageOpenGLQuartz
BridgesRubyPython
NetworkingBonjourKerberos
![Page 22: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/22.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/23.jpg)
Xcode
General IDECode EditorLLVM Engine IntegrationInterface Builder IntegrationProject Navigation
UtilitiesVersion EditorInstruments
![Page 24: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/24.jpg)
Xcode
![Page 25: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/25.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/26.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/27.jpg)
Interface Builder
![Page 28: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/28.jpg)
Design
Objective-C and Cocoa utilize many design patterns and constructs
Provides stability and familiarity
Design PatternsModel-View-ControllerDelegationOthers…
![Page 29: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/29.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/30.jpg)
Model-View-Controller
Smalltalk-80 MVC Paradigm
ParcPlace Systems, Inc.
![Page 31: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/31.jpg)
Model-View-Controller
Controller
Model View
Action
UpdateNotify
Update
Observer
Mediator
Command
![Page 32: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/32.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/33.jpg)
Design Patterns
Command patternNSInvocationUndo/redo
Observer patternKVO: Key-Value Observer
Adapter patternProtocols
Singleton PatternNSFileManagerNSApplication
MementoArchivingSerialization
ProxyNSProxy
![Page 34: OS X Development](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/34.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062422/56813cdf550346895da68567/html5/thumbnails/35.jpg)
Demo