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
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de JavascriptBernard Loire
 

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
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
 

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

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Recently uploaded (20)

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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