SlideShare a Scribd company logo
1 of 13
Download to read offline
Objective C for Samurais by @rafaecheve
10 Ways to Improve
Objective C Code
2.0
Saturday, July 13, 13
Objective C for Samurais by @rafaecheve
Understand Objective C
• Objective-C is a superset of C
• Verbosity is a must
• Long names is a must
• It is damn old
Saturday, July 13, 13
tip #1
@class PETDog;
Avoid Importing Headers on .h files when possible.
Instead of importing .h files you can use @class to tell the compiler to use
this class.
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
NSNumber *intNumber = @3;
NSNumber *floatNumber = @5.5f;
NSNumber *doubleNumber = @3.14;
NSNumber *boolNumber = @YES;
NSNumber *charNumber = @'b';
NSArray *animals = [NSArray arrayWithObjects:@"ocelot", @"lion",
@"tiger", @"donkey", nil];
NSDictionary *geekinfo = @{@"firstName" : @"Rafael", @"lastName" :
@"Echeverria", @"age" : @24};
tip #2 Use Objective 2.0 literals on your declaring needs.
NSString *greeting = @"Awesome Dog";
Since Objective C 2.0 you can declare variables in literal Style.
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #3
//.h
extern const NSString ABCDogName;
//.m
const NSString ABCDogName = 0.3;
#define MIDI_DURATION 1.0
Use typed constants and defeat lazyness
Declare constants as typed, and prevend collisions and uncertainty with
created by #define.
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #4
enum ABCDogState {
ABCDogStateBarking,
ABCDogStateSleeping,
ABCDogStateEating,
};
switch (_currentState) {
ABCDogStateBarking:
// Handle barking state
break;
ABCDogStateSleeping:
// Handle sleeping state
break;
ABCDogStateEating:
// Handle eating state
break;
}
Enumerate as long you know the status.
Enumerate safely when you know your diferent values for Opcions and
States. it is very common to use it on switch statements.
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #5 Take the time to understatang property attributes.
readonly Only a getter is available, and the compiler will generate
it only if the property is synthesized.
readwrite
Both a getter and a setter are available. If the property
is synthesized, the compiler will generate both
methods.
copy This designates an owning relationship similar to strong;
however, instead of retaining the value, it is copied.
unsafe_unretained
This has the same semantics as assign but is used
where the type is an object type to indicate a
nonowning relationship (unretained).
assign The setter is a simple assign operation used for scalar
types, such as CGFloat or NSInteger.
strong
This designates that the property defines an owning
relationship. When a new value is set, it is first
retained, the old value is released, and then the value
is set.
weak This designates that the property defines a nonowning
relationship.
We can assing our properties with diferent properties, as desired.
Saturday, July 13, 13
tip #6
NSString *foo = @"Badger 123";
NSString *bar = [NSString stringWithFormat:@"Badger %i", 123];
BOOL equalA = (foo == bar); //< equalA = NO
BOOL equalB = [foo isEqual:bar]; //< equalB = YES
BOOL equalC = [foo isEqualToString:bar]; //< equalC = YES
Objects are equal under diferent circumstances.
Understanting equality is always important to avoid pitfalls at comparing.
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #7
@interface ABCDogBreedChihuahua : ABCDog
@end
@implementation ABCDogBreedChihuahua
- (void) doBark {
[self sayHola];
}
@end
Hide your implentation using the Class Cluster Pattern
typedef NS_ENUM(NSUInteger, ABCDogBreed) {
ABCDogBreedChihuahua,
ABCDogBreedLabrador,
};
@interface ABCDog : NSObject
@property (copy) NSString *name;
// Factory Method to create dogs
+ (ABCDog*)dogWithBreed:(ABCDogBreed)type;
- (void)doBark;
@end
@implementation ABCDog
+ (ABCDog*)dogWithBreed:(ABCDogBreed)type{
switch (type) {
case EOCEmployeeTypeDeveloper:
return [ABCDogBreedChihuahua new];
break;
case EOCEmployeeTypeDesigner:
return [ABCDogBreedLabrador new];
break;
}
}
- (void) doBark {
// Subclasses implement this.
}
.h
.m
subclass
This can save tons of lines and helps to keep things DRY
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #8
NSMutableDictionary *dict = [NSMutableDictionary new];
[dict isMemberOfClass:[NSDictionary class]]; ///< NO
[dict isMemberOfClass:[NSMutableDictionary class]]; ///< YES
[dict isKindOfClass:[NSDictionary class]]; ///< YES
[dict isKindOfClass:[NSArray class]]; ///< NO
Use Inspection to reveal class secrets.
Understanding how to inspect a class is a powerful tecnique
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #9 Use Prefix to avoid class clashes.
Use the name of your app, or company name is up to you.
ABCDog
ABCCat
ABCDonkey
com.bigco.myapp
BCOPerson
com.abcinc.myapp
BCOJob
BCOAccount
Objective C for Samurais by @rafaecheve
Saturday, July 13, 13
tip #10
- (id)initWithName:(NSString *)name
andAge:(NSNumber)age {
if ((self = [super init])) {
_name = name;
_age = age;
}
return self;
}
Customize you initializers as needed
This allows you to create you objects easly using what you want.
Objective C for Samurais by @rafaecheve
- (id)initWithName:(NSString *)name
andAge:(NSNumber)age
Saturday, July 13, 13
More Techniques:
@rafaecheve
r@afaecheve.com
rafaecheve.com
http://www.slideshare.net/rafaechev
Saturday, July 13, 13

More Related Content

Viewers also liked

Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclassxds2000
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object ArchitecturesMarcus Denker
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languagesAnkit Pandey
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)lqi
 
April iOS Meetup - UIAppearance Presentation
April iOS Meetup - UIAppearance PresentationApril iOS Meetup - UIAppearance Presentation
April iOS Meetup - UIAppearance PresentationLong Weekend LLC
 
C optimization notes
C optimization notesC optimization notes
C optimization notesFyaz Ghaffar
 
Code Optimization using Code Re-ordering
Code Optimization using Code Re-orderingCode Optimization using Code Re-ordering
Code Optimization using Code Re-orderingArangs Manickam
 
Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankarDipankar Nalui
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 
Protein Structure & Function
Protein Structure & FunctionProtein Structure & Function
Protein Structure & Functioniptharis
 

Viewers also liked (18)

Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclass
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object Architectures
 
Pragmatic blocks
Pragmatic blocksPragmatic blocks
Pragmatic blocks
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
Understanding Metaclasses
Understanding MetaclassesUnderstanding Metaclasses
Understanding Metaclasses
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)
 
April iOS Meetup - UIAppearance Presentation
April iOS Meetup - UIAppearance PresentationApril iOS Meetup - UIAppearance Presentation
April iOS Meetup - UIAppearance Presentation
 
C optimization notes
C optimization notesC optimization notes
C optimization notes
 
Objective runtime
Objective runtimeObjective runtime
Objective runtime
 
Code Optimization using Code Re-ordering
Code Optimization using Code Re-orderingCode Optimization using Code Re-ordering
Code Optimization using Code Re-ordering
 
Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankar
 
Optimization
OptimizationOptimization
Optimization
 
optimization c code on blackfin
optimization c code on blackfinoptimization c code on blackfin
optimization c code on blackfin
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
 
Protein Structure & Function
Protein Structure & FunctionProtein Structure & Function
Protein Structure & Function
 

Similar to Objective C for Samurais

Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Railselliando dias
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
iOS best practices
iOS best practicesiOS best practices
iOS best practicesMaxim Vialyx
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General IntroductionThomas Johnston
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Arthur Puthin
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsAjax Experience 2009
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVMAndres Almiray
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...Richard McIntyre
 
Better rspec 進擊的 RSpec
Better rspec 進擊的 RSpecBetter rspec 進擊的 RSpec
Better rspec 進擊的 RSpecLi Hsuan Hung
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyAndres Almiray
 
Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingMike Clement
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new featuresShivam Goel
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Languagezone
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoobirbal
 

Similar to Objective C for Samurais (20)

Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...What is this DI and AOP stuff anyway...
What is this DI and AOP stuff anyway...
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
 
Better rspec 進擊的 RSpec
Better rspec 進擊的 RSpecBetter rspec 進擊的 RSpec
Better rspec 進擊的 RSpec
 
Java generics final
Java generics finalJava generics final
Java generics final
 
Cleancode
CleancodeCleancode
Cleancode
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
 
Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
 
The Java Script Programming Language
The  Java Script  Programming  LanguageThe  Java Script  Programming  Language
The Java Script Programming Language
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 

More from rafaecheve

Entering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup EcosystemEntering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup Ecosystemrafaecheve
 
Productividad al Emprender
Productividad al EmprenderProductividad al Emprender
Productividad al Emprenderrafaecheve
 
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0rafaecheve
 
Cooperativas de Plataforma
Cooperativas de Plataforma Cooperativas de Plataforma
Cooperativas de Plataforma rafaecheve
 
Innovar en 2021: Transformaciones a tomar en cuenta
Innovar en 2021: Transformaciones a tomar en cuentaInnovar en 2021: Transformaciones a tomar en cuenta
Innovar en 2021: Transformaciones a tomar en cuentarafaecheve
 
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del Sureste
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del SuresteFabricas de Economía Solidaria: La Oportunidad para las Comunidades del Sureste
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del Suresterafaecheve
 
Liderazgo de Instituciones hacia la Sociedad 5.0
Liderazgo de Instituciones hacia la Sociedad 5.0Liderazgo de Instituciones hacia la Sociedad 5.0
Liderazgo de Instituciones hacia la Sociedad 5.0rafaecheve
 
Innovación y Las Industrias: Acceso al Ecosistema desde la Academia
Innovación y Las Industrias: Acceso al Ecosistema desde la AcademiaInnovación y Las Industrias: Acceso al Ecosistema desde la Academia
Innovación y Las Industrias: Acceso al Ecosistema desde la Academiarafaecheve
 
Emprendiendo en Tabasco
Emprendiendo en TabascoEmprendiendo en Tabasco
Emprendiendo en Tabascorafaecheve
 
Innovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno AbiertoInnovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno Abiertorafaecheve
 
Foro Gobierno Abierto Tabasco
Foro Gobierno Abierto TabascoForo Gobierno Abierto Tabasco
Foro Gobierno Abierto Tabascorafaecheve
 
Bitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO VillahermosaBitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO Villahermosarafaecheve
 
Bitcoin Cash el Futuro del Dinero en la UVG
Bitcoin Cash el Futuro del Dinero en la UVGBitcoin Cash el Futuro del Dinero en la UVG
Bitcoin Cash el Futuro del Dinero en la UVGrafaecheve
 
Comunidades de Emprendimiento Talent Night Yucatán
Comunidades de Emprendimiento Talent Night YucatánComunidades de Emprendimiento Talent Night Yucatán
Comunidades de Emprendimiento Talent Night Yucatánrafaecheve
 
Innovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el EmprendimientoInnovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el Emprendimientorafaecheve
 
Tu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y PersonalizaTu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y Personalizarafaecheve
 
Desarrollando para la plataforma de Stellar
Desarrollando para la plataforma de StellarDesarrollando para la plataforma de Stellar
Desarrollando para la plataforma de Stellarrafaecheve
 
30 Ideas para hackear tu ecosistema de emprendimiento
30 Ideas para hackear tu ecosistema de emprendimiento30 Ideas para hackear tu ecosistema de emprendimiento
30 Ideas para hackear tu ecosistema de emprendimientorafaecheve
 
Herramientas para Emprender desde 0
Herramientas para Emprender desde 0Herramientas para Emprender desde 0
Herramientas para Emprender desde 0rafaecheve
 
Bitcoin Cash Llega a Villahermosa | Cryptos Tabasco
Bitcoin Cash Llega a Villahermosa | Cryptos TabascoBitcoin Cash Llega a Villahermosa | Cryptos Tabasco
Bitcoin Cash Llega a Villahermosa | Cryptos Tabascorafaecheve
 

More from rafaecheve (20)

Entering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup EcosystemEntering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup Ecosystem
 
Productividad al Emprender
Productividad al EmprenderProductividad al Emprender
Productividad al Emprender
 
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0
El papel de una Ingeniería en Sistemas Computacionales en la Industria 4.0
 
Cooperativas de Plataforma
Cooperativas de Plataforma Cooperativas de Plataforma
Cooperativas de Plataforma
 
Innovar en 2021: Transformaciones a tomar en cuenta
Innovar en 2021: Transformaciones a tomar en cuentaInnovar en 2021: Transformaciones a tomar en cuenta
Innovar en 2021: Transformaciones a tomar en cuenta
 
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del Sureste
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del SuresteFabricas de Economía Solidaria: La Oportunidad para las Comunidades del Sureste
Fabricas de Economía Solidaria: La Oportunidad para las Comunidades del Sureste
 
Liderazgo de Instituciones hacia la Sociedad 5.0
Liderazgo de Instituciones hacia la Sociedad 5.0Liderazgo de Instituciones hacia la Sociedad 5.0
Liderazgo de Instituciones hacia la Sociedad 5.0
 
Innovación y Las Industrias: Acceso al Ecosistema desde la Academia
Innovación y Las Industrias: Acceso al Ecosistema desde la AcademiaInnovación y Las Industrias: Acceso al Ecosistema desde la Academia
Innovación y Las Industrias: Acceso al Ecosistema desde la Academia
 
Emprendiendo en Tabasco
Emprendiendo en TabascoEmprendiendo en Tabasco
Emprendiendo en Tabasco
 
Innovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno AbiertoInnovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno Abierto
 
Foro Gobierno Abierto Tabasco
Foro Gobierno Abierto TabascoForo Gobierno Abierto Tabasco
Foro Gobierno Abierto Tabasco
 
Bitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO VillahermosaBitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO Villahermosa
 
Bitcoin Cash el Futuro del Dinero en la UVG
Bitcoin Cash el Futuro del Dinero en la UVGBitcoin Cash el Futuro del Dinero en la UVG
Bitcoin Cash el Futuro del Dinero en la UVG
 
Comunidades de Emprendimiento Talent Night Yucatán
Comunidades de Emprendimiento Talent Night YucatánComunidades de Emprendimiento Talent Night Yucatán
Comunidades de Emprendimiento Talent Night Yucatán
 
Innovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el EmprendimientoInnovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el Emprendimiento
 
Tu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y PersonalizaTu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y Personaliza
 
Desarrollando para la plataforma de Stellar
Desarrollando para la plataforma de StellarDesarrollando para la plataforma de Stellar
Desarrollando para la plataforma de Stellar
 
30 Ideas para hackear tu ecosistema de emprendimiento
30 Ideas para hackear tu ecosistema de emprendimiento30 Ideas para hackear tu ecosistema de emprendimiento
30 Ideas para hackear tu ecosistema de emprendimiento
 
Herramientas para Emprender desde 0
Herramientas para Emprender desde 0Herramientas para Emprender desde 0
Herramientas para Emprender desde 0
 
Bitcoin Cash Llega a Villahermosa | Cryptos Tabasco
Bitcoin Cash Llega a Villahermosa | Cryptos TabascoBitcoin Cash Llega a Villahermosa | Cryptos Tabasco
Bitcoin Cash Llega a Villahermosa | Cryptos Tabasco
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Objective C for Samurais

  • 1. Objective C for Samurais by @rafaecheve 10 Ways to Improve Objective C Code 2.0 Saturday, July 13, 13
  • 2. Objective C for Samurais by @rafaecheve Understand Objective C • Objective-C is a superset of C • Verbosity is a must • Long names is a must • It is damn old Saturday, July 13, 13
  • 3. tip #1 @class PETDog; Avoid Importing Headers on .h files when possible. Instead of importing .h files you can use @class to tell the compiler to use this class. Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 4. NSNumber *intNumber = @3; NSNumber *floatNumber = @5.5f; NSNumber *doubleNumber = @3.14; NSNumber *boolNumber = @YES; NSNumber *charNumber = @'b'; NSArray *animals = [NSArray arrayWithObjects:@"ocelot", @"lion", @"tiger", @"donkey", nil]; NSDictionary *geekinfo = @{@"firstName" : @"Rafael", @"lastName" : @"Echeverria", @"age" : @24}; tip #2 Use Objective 2.0 literals on your declaring needs. NSString *greeting = @"Awesome Dog"; Since Objective C 2.0 you can declare variables in literal Style. Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 5. tip #3 //.h extern const NSString ABCDogName; //.m const NSString ABCDogName = 0.3; #define MIDI_DURATION 1.0 Use typed constants and defeat lazyness Declare constants as typed, and prevend collisions and uncertainty with created by #define. Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 6. tip #4 enum ABCDogState { ABCDogStateBarking, ABCDogStateSleeping, ABCDogStateEating, }; switch (_currentState) { ABCDogStateBarking: // Handle barking state break; ABCDogStateSleeping: // Handle sleeping state break; ABCDogStateEating: // Handle eating state break; } Enumerate as long you know the status. Enumerate safely when you know your diferent values for Opcions and States. it is very common to use it on switch statements. Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 7. tip #5 Take the time to understatang property attributes. readonly Only a getter is available, and the compiler will generate it only if the property is synthesized. readwrite Both a getter and a setter are available. If the property is synthesized, the compiler will generate both methods. copy This designates an owning relationship similar to strong; however, instead of retaining the value, it is copied. unsafe_unretained This has the same semantics as assign but is used where the type is an object type to indicate a nonowning relationship (unretained). assign The setter is a simple assign operation used for scalar types, such as CGFloat or NSInteger. strong This designates that the property defines an owning relationship. When a new value is set, it is first retained, the old value is released, and then the value is set. weak This designates that the property defines a nonowning relationship. We can assing our properties with diferent properties, as desired. Saturday, July 13, 13
  • 8. tip #6 NSString *foo = @"Badger 123"; NSString *bar = [NSString stringWithFormat:@"Badger %i", 123]; BOOL equalA = (foo == bar); //< equalA = NO BOOL equalB = [foo isEqual:bar]; //< equalB = YES BOOL equalC = [foo isEqualToString:bar]; //< equalC = YES Objects are equal under diferent circumstances. Understanting equality is always important to avoid pitfalls at comparing. Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 9. tip #7 @interface ABCDogBreedChihuahua : ABCDog @end @implementation ABCDogBreedChihuahua - (void) doBark { [self sayHola]; } @end Hide your implentation using the Class Cluster Pattern typedef NS_ENUM(NSUInteger, ABCDogBreed) { ABCDogBreedChihuahua, ABCDogBreedLabrador, }; @interface ABCDog : NSObject @property (copy) NSString *name; // Factory Method to create dogs + (ABCDog*)dogWithBreed:(ABCDogBreed)type; - (void)doBark; @end @implementation ABCDog + (ABCDog*)dogWithBreed:(ABCDogBreed)type{ switch (type) { case EOCEmployeeTypeDeveloper: return [ABCDogBreedChihuahua new]; break; case EOCEmployeeTypeDesigner: return [ABCDogBreedLabrador new]; break; } } - (void) doBark { // Subclasses implement this. } .h .m subclass This can save tons of lines and helps to keep things DRY Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 10. tip #8 NSMutableDictionary *dict = [NSMutableDictionary new]; [dict isMemberOfClass:[NSDictionary class]]; ///< NO [dict isMemberOfClass:[NSMutableDictionary class]]; ///< YES [dict isKindOfClass:[NSDictionary class]]; ///< YES [dict isKindOfClass:[NSArray class]]; ///< NO Use Inspection to reveal class secrets. Understanding how to inspect a class is a powerful tecnique Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 11. tip #9 Use Prefix to avoid class clashes. Use the name of your app, or company name is up to you. ABCDog ABCCat ABCDonkey com.bigco.myapp BCOPerson com.abcinc.myapp BCOJob BCOAccount Objective C for Samurais by @rafaecheve Saturday, July 13, 13
  • 12. tip #10 - (id)initWithName:(NSString *)name andAge:(NSNumber)age { if ((self = [super init])) { _name = name; _age = age; } return self; } Customize you initializers as needed This allows you to create you objects easly using what you want. Objective C for Samurais by @rafaecheve - (id)initWithName:(NSString *)name andAge:(NSNumber)age Saturday, July 13, 13