SlideShare a Scribd company logo
Introduction to OS X development with Cocoa … and how web developers  can cheat George Brocklehurst http://georgebrock.com  @georgebrock on Twitter
Before we start… Have you done any… HTML? Javascript? PHP? Any object oriented programming? C?
What is Cocoa? Framework for Mac OS X and iPhone Heavily MVC focused Usually written in Objective-C Can also be written in Python or Ruby
Getting Started You will need: Apple’s Xcode Tools Available from: http://developer.apple.com/technology/xcode.html Your OS X install DVDs
Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end
Objective C Syntax: Classes Declaring a class interface (.h file) @interface  MyClass : NSObject { int anInteger; } - (void)doStuff; @end Interface only here!
Objective C Syntax: Classes Declaring a class interface (.h file) @interface  MyClass  : NSObject { int anInteger; } - (void)doStuff; @end Class name
Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass :  NSObject { int anInteger; } - (void)doStuff; @end Parent class
Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Members
Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Methods
Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end
Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end Interface
Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end Start class implementation
Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass - (void)doStuff { // Do stuff here } @end Methods with bodies
Objective C Syntax: Methods -(void)myMethod:(int)arg In other languages, might be: function myMethod(arg)
Objective C Syntax: Methods - (void)myMethod:(int)arg Can be either: +  for a class method -  for an instance method Method scope
Objective C Syntax: Methods -( void )myMethod:(int)arg Can be any valid data type, including: void  returns nothing id  a pointer to an object of any class NSString*  a pointer to an NSString BOOL  a boolean  ( TRUE ,  FALSE ,  YES  or  NO ) Return type
Objective C Syntax: Methods -(void) myMethod: (int)arg Colons precede arguments, but are considered part of the method name Method name
Objective C Syntax: Methods -(void)myMethod: (int)arg Come after or within the method name For multiple arguments: -(void)myMethod: (int)arg  andAlso: (int)arg2 (Method name is “myMethod:andAlso:”) Argument type Argument name
Objective C Syntax: Methods -(void)myMethod:(int)arg1  andAlso:(int)arg2; How to call this method: [myObject myMethod:10 andAlso:20]; In other languages this might be: myObject->myMethod(10, 20);  //or myObject.myMethod(10, 20);
Objective C Syntax: Properties New short hand in Objective-C 2.0 (Xcode 3 / Leopard) Access class members without writing getters and setters Convenient, but nasty difficult to remember syntax
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”;
Objective C Syntax: Properties In the class interface (with methods): @property( copy , readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Storage method:  assign ,  retain  or  copy
Objective C Syntax: Properties In the class interface (with methods): @property(copy,  readwrite ) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Access permissions:  readwrite  or  readonly
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Can add other things:  nonatomic ,  getter=…  and  setter=…
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite)  NSString *propertyName ; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Property variable declaration, must also be declared as a class member
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize  propertyName; To access: myInstance.propertyName = @”Foo”; Tell Objective-C precompiler to make getter & setter
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”;
Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance . propertyName = @”Foo”; Sensible syntax! Yay!
Objective C Syntax: Selectors SEL callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior
Objective C Syntax: Selectors SEL  callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior Data type for selectors
Objective C Syntax: Selectors SEL callback = NULL; callback =  @selector( myMethod:andAlso: ) ; Like function pointers Useful for callback type behavior Macro to create selector
Objective C Syntax: Selectors SEL callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior
Objective C Syntax: Strings NSString *myString; myString =  @”This is a string” ; Note the  @  prefix Tells the Objective-C precompiler to instantiate an NSString instead of just creating a C string (aka. A nasty character array)
Managing Memory Easier than vanilla C, honest! Reference counting Increment with  retain , decrement with  release Rule of thumb:  release   anything you  alloc ,   copy   or   retain
Managing Memory: Example NSString *str; str = [NSString  alloc ];  //1 [str  retain ];  //2 [str  release ];  //1 [str  release ], str = nil; //0
Managing Memory: Autorelease [str autorelease]; This will automatically release an object when it’s finished with Another rule of thumb: [NSThing thingWith:…] returns an autoreleased instance [[NSThing alloc] initWith:…]   needs manually releasing
Wasn’t there something about cheating?! WebKit is part of Cocoa Can build your UI with HTML, CSS and Javascript and only use Objective-C when you really need to
Demo
I Can Haz Questions?
K, Thx, Bai! George Brocklehurst http://georgebrock.com @georgebrock on Twitter

More Related Content

What's hot (20)

PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
GeorgePeterBanyard
 
Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
Roman Okolovich
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan Rüegg
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
Nico Ludwig
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
RameshNair6
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
Jussi Pohjolainen
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
LogeekNightUkraine
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
Envision Computer Training Institute
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
Jack Nutting
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
Hadziq Fabroyir
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
Princess Sam
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
corehard_by
 
C++ Language
C++ LanguageC++ Language
C++ Language
Vidyacenter
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
Carson Wilber
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
GeorgePeterBanyard
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan Rüegg
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
Nico Ludwig
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
RameshNair6
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
Jussi Pohjolainen
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
LogeekNightUkraine
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
Hadziq Fabroyir
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
Princess Sam
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
corehard_by
 

Viewers also liked (15)

Fotos super estranhas- um show de Photoshop
Fotos super estranhas- um show de PhotoshopFotos super estranhas- um show de Photoshop
Fotos super estranhas- um show de Photoshop
luh_olveira88
 
N\'est Pas
N\'est PasN\'est Pas
N\'est Pas
guest8a8b88
 
0864562- April Fools
0864562- April Fools0864562- April Fools
0864562- April Fools
Ali G
 
ΤΑ ΑΥΤΑ
ΤΑ ΑΥΤΑΤΑ ΑΥΤΑ
ΤΑ ΑΥΤΑ
iohannesgg
 
If i were 22
If i were 22If i were 22
If i were 22
Bruno Simoni
 
Ebooks DIY Example
Ebooks DIY ExampleEbooks DIY Example
Ebooks DIY Example
Yoshinari Takaoka
 
Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk Visioonist Lahendusteni 2008Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk
 
Illusions [Ao Giac]
Illusions [Ao Giac]Illusions [Ao Giac]
Illusions [Ao Giac]
guestdb0255
 
0848110 Snowboarding: The Passion of the winter
0848110 Snowboarding: The Passion of the winter0848110 Snowboarding: The Passion of the winter
0848110 Snowboarding: The Passion of the winter
Ali G
 
Agopuntura E Prestazione Sportiva
Agopuntura E Prestazione SportivaAgopuntura E Prestazione Sportiva
Agopuntura E Prestazione Sportiva
Alessandro Corsini
 
Vestits
VestitsVestits
Vestits
manaid
 
debugging server with strace
debugging server with stracedebugging server with strace
debugging server with strace
Yoshinari Takaoka
 
Fabric Essentials
Fabric EssentialsFabric Essentials
Fabric Essentials
Yoshinari Takaoka
 
Fotos super estranhas- um show de Photoshop
Fotos super estranhas- um show de PhotoshopFotos super estranhas- um show de Photoshop
Fotos super estranhas- um show de Photoshop
luh_olveira88
 
0864562- April Fools
0864562- April Fools0864562- April Fools
0864562- April Fools
Ali G
 
Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk Visioonist Lahendusteni 2008Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk Visioonist Lahendusteni 2008
Alar Kolk
 
Illusions [Ao Giac]
Illusions [Ao Giac]Illusions [Ao Giac]
Illusions [Ao Giac]
guestdb0255
 
0848110 Snowboarding: The Passion of the winter
0848110 Snowboarding: The Passion of the winter0848110 Snowboarding: The Passion of the winter
0848110 Snowboarding: The Passion of the winter
Ali G
 
Agopuntura E Prestazione Sportiva
Agopuntura E Prestazione SportivaAgopuntura E Prestazione Sportiva
Agopuntura E Prestazione Sportiva
Alessandro Corsini
 
Vestits
VestitsVestits
Vestits
manaid
 
debugging server with strace
debugging server with stracedebugging server with strace
debugging server with strace
Yoshinari Takaoka
 

Similar to Cocoa for Web Developers (20)

Objective c
Objective cObjective c
Objective c
ricky_chatur2005
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
Asim Rais Siddiqui
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
Hussain Behestee
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
Muhammad Abdullah
 
05 Object Oriented Concept Presentation.pptx
05 Object Oriented Concept Presentation.pptx05 Object Oriented Concept Presentation.pptx
05 Object Oriented Concept Presentation.pptx
ToranSahu18
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
Javier Gonzalez-Sanchez
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
shubhra chauhan
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
arjun431527
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
Compare Infobase Limited
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Howard Lewis Ship
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
 
Objective c
Objective cObjective c
Objective c
Stijn
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
Synapseindiappsdevelopment
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guide
Tiago Faller
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
sikkim manipal university
 
C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
Mark Whitaker
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Connex
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
Muhammad Abdullah
 
05 Object Oriented Concept Presentation.pptx
05 Object Oriented Concept Presentation.pptx05 Object Oriented Concept Presentation.pptx
05 Object Oriented Concept Presentation.pptx
ToranSahu18
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
arjun431527
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Howard Lewis Ship
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
 
Objective c
Objective cObjective c
Objective c
Stijn
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guide
Tiago Faller
 
C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
Mark Whitaker
 

Recently uploaded (20)

HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 

Cocoa for Web Developers

  • 1. Introduction to OS X development with Cocoa … and how web developers can cheat George Brocklehurst http://georgebrock.com @georgebrock on Twitter
  • 2. Before we start… Have you done any… HTML? Javascript? PHP? Any object oriented programming? C?
  • 3. What is Cocoa? Framework for Mac OS X and iPhone Heavily MVC focused Usually written in Objective-C Can also be written in Python or Ruby
  • 4. Getting Started You will need: Apple’s Xcode Tools Available from: http://developer.apple.com/technology/xcode.html Your OS X install DVDs
  • 5. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end
  • 6. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Interface only here!
  • 7. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Class name
  • 8. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Parent class
  • 9. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Members
  • 10. Objective C Syntax: Classes Declaring a class interface (.h file) @interface MyClass : NSObject { int anInteger; } - (void)doStuff; @end Methods
  • 11. Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end
  • 12. Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end Interface
  • 13. Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass (void)doStuff { // Do stuff here } @end Start class implementation
  • 14. Objective C Syntax: Classes Implementing a class (.m file) #import “MyClass.h” @implementation MyClass - (void)doStuff { // Do stuff here } @end Methods with bodies
  • 15. Objective C Syntax: Methods -(void)myMethod:(int)arg In other languages, might be: function myMethod(arg)
  • 16. Objective C Syntax: Methods - (void)myMethod:(int)arg Can be either: + for a class method - for an instance method Method scope
  • 17. Objective C Syntax: Methods -( void )myMethod:(int)arg Can be any valid data type, including: void returns nothing id a pointer to an object of any class NSString* a pointer to an NSString BOOL a boolean ( TRUE , FALSE , YES or NO ) Return type
  • 18. Objective C Syntax: Methods -(void) myMethod: (int)arg Colons precede arguments, but are considered part of the method name Method name
  • 19. Objective C Syntax: Methods -(void)myMethod: (int)arg Come after or within the method name For multiple arguments: -(void)myMethod: (int)arg andAlso: (int)arg2 (Method name is “myMethod:andAlso:”) Argument type Argument name
  • 20. Objective C Syntax: Methods -(void)myMethod:(int)arg1 andAlso:(int)arg2; How to call this method: [myObject myMethod:10 andAlso:20]; In other languages this might be: myObject->myMethod(10, 20); //or myObject.myMethod(10, 20);
  • 21. Objective C Syntax: Properties New short hand in Objective-C 2.0 (Xcode 3 / Leopard) Access class members without writing getters and setters Convenient, but nasty difficult to remember syntax
  • 22. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”;
  • 23. Objective C Syntax: Properties In the class interface (with methods): @property( copy , readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Storage method: assign , retain or copy
  • 24. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite ) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Access permissions: readwrite or readonly
  • 25. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Can add other things: nonatomic , getter=… and setter=…
  • 26. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName ; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Property variable declaration, must also be declared as a class member
  • 27. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”; Tell Objective-C precompiler to make getter & setter
  • 28. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance.propertyName = @”Foo”;
  • 29. Objective C Syntax: Properties In the class interface (with methods): @property(copy, readwrite) NSString *propertyName; In the class implementation: @synthesize propertyName; To access: myInstance . propertyName = @”Foo”; Sensible syntax! Yay!
  • 30. Objective C Syntax: Selectors SEL callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior
  • 31. Objective C Syntax: Selectors SEL callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior Data type for selectors
  • 32. Objective C Syntax: Selectors SEL callback = NULL; callback = @selector( myMethod:andAlso: ) ; Like function pointers Useful for callback type behavior Macro to create selector
  • 33. Objective C Syntax: Selectors SEL callback = NULL; callback = @selector(myMethod:andAlso:); Like function pointers Useful for callback type behavior
  • 34. Objective C Syntax: Strings NSString *myString; myString = @”This is a string” ; Note the @ prefix Tells the Objective-C precompiler to instantiate an NSString instead of just creating a C string (aka. A nasty character array)
  • 35. Managing Memory Easier than vanilla C, honest! Reference counting Increment with retain , decrement with release Rule of thumb: release anything you alloc , copy or retain
  • 36. Managing Memory: Example NSString *str; str = [NSString alloc ]; //1 [str retain ]; //2 [str release ]; //1 [str release ], str = nil; //0
  • 37. Managing Memory: Autorelease [str autorelease]; This will automatically release an object when it’s finished with Another rule of thumb: [NSThing thingWith:…] returns an autoreleased instance [[NSThing alloc] initWith:…] needs manually releasing
  • 38. Wasn’t there something about cheating?! WebKit is part of Cocoa Can build your UI with HTML, CSS and Javascript and only use Objective-C when you really need to
  • 39. Demo
  • 40. I Can Haz Questions?
  • 41. K, Thx, Bai! George Brocklehurst http://georgebrock.com @georgebrock on Twitter