SlideShare a Scribd company logo
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 (18)

Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclass
xds2000
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object Architectures
Marcus Denker
 
Pragmatic blocks
Pragmatic blocksPragmatic blocks
Pragmatic blocks
Robert Brown
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
The World of Smalltalk
 
Understanding Metaclasses
Understanding MetaclassesUnderstanding Metaclasses
Understanding Metaclasses
Daniel Neuhäuser
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit 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 Presentation
Long Weekend LLC
 
C optimization notes
C optimization notesC optimization notes
C optimization notes
Fyaz Ghaffar
 
Objective runtime
Objective runtimeObjective runtime
Objective runtime
Michael Shieh
 
Code Optimization using Code Re-ordering
Code Optimization using Code Re-orderingCode Optimization using Code Re-ordering
Code Optimization using Code Re-ordering
Arangs Manickam
 
Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankar
Dipankar Nalui
 
Optimization
OptimizationOptimization
Optimization
Royalzig Luxury Furniture
 
optimization c code on blackfin
optimization c code on blackfinoptimization c code on blackfin
optimization c code on blackfin
Pantech ProLabs India Pvt Ltd
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
Satyamevjayte Haxor
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
Emertxe Information Technologies Pvt Ltd
 
Protein Structure & Function
Protein Structure & FunctionProtein Structure & Function
Protein Structure & Function
iptharis
 
Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclass
xds2000
 
The meta of Meta-object Architectures
The meta of Meta-object ArchitecturesThe meta of Meta-object Architectures
The meta of Meta-object Architectures
Marcus Denker
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit 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 Presentation
Long Weekend LLC
 
C optimization notes
C optimization notesC optimization notes
C optimization notes
Fyaz Ghaffar
 
Code Optimization using Code Re-ordering
Code Optimization using Code Re-orderingCode Optimization using Code Re-ordering
Code Optimization using Code Re-ordering
Arangs Manickam
 
Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankar
Dipankar Nalui
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 
Protein Structure & Function
Protein Structure & FunctionProtein Structure & Function
Protein Structure & Function
iptharis
 

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
elliando 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 1
Troy Miles
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
Maxim Vialyx
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
Thomas 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 Goodparts
Ajax Experience 2009
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
Andres Almiray
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David 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
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
Gunjan Kumar
 
Better rspec 進擊的 RSpec
Better rspec 進擊的 RSpecBetter rspec 進擊的 RSpec
Better rspec 進擊的 RSpec
Li Hsuan Hung
 
Java generics final
Java generics finalJava generics final
Java generics final
Akshay Chaudhari
 
Cleancode
CleancodeCleancode
Cleancode
hendrikvb
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Andres 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 Testing
Mike Clement
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
Shivam Goel
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
Bernard Loire
 
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
elliando 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 1
Troy Miles
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
Maxim Vialyx
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
Thomas 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 Goodparts
Ajax Experience 2009
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
Andres Almiray
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David 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 進擊的 RSpec
Li Hsuan Hung
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
Andres 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 Testing
Mike Clement
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
Shivam Goel
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Raghavan Mohan
 
Les origines de Javascript
Les origines de JavascriptLes origines de Javascript
Les origines de Javascript
Bernard Loire
 

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
rafaecheve
 
Productividad al Emprender
Productividad al EmprenderProductividad al Emprender
Productividad al Emprender
rafaecheve
 
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
rafaecheve
 
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 cuenta
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
Emprendiendo en Tabasco
Emprendiendo en TabascoEmprendiendo en Tabasco
Emprendiendo en Tabasco
rafaecheve
 
Innovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno AbiertoInnovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno Abierto
rafaecheve
 
Foro Gobierno Abierto Tabasco
Foro Gobierno Abierto TabascoForo Gobierno Abierto Tabasco
Foro Gobierno Abierto Tabasco
rafaecheve
 
Bitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO VillahermosaBitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO Villahermosa
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
Innovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el EmprendimientoInnovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el Emprendimiento
rafaecheve
 
Tu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y PersonalizaTu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y Personaliza
rafaecheve
 
Desarrollando para la plataforma de Stellar
Desarrollando para la plataforma de StellarDesarrollando para la plataforma de Stellar
Desarrollando para la plataforma de Stellar
rafaecheve
 
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
rafaecheve
 
Herramientas para Emprender desde 0
Herramientas para Emprender desde 0Herramientas para Emprender desde 0
Herramientas para Emprender desde 0
rafaecheve
 
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
rafaecheve
 
Entering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup EcosystemEntering the Mexican Southeast Startup Ecosystem
Entering the Mexican Southeast Startup Ecosystem
rafaecheve
 
Productividad al Emprender
Productividad al EmprenderProductividad al Emprender
Productividad al Emprender
rafaecheve
 
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
rafaecheve
 
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 cuenta
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
Emprendiendo en Tabasco
Emprendiendo en TabascoEmprendiendo en Tabasco
Emprendiendo en Tabasco
rafaecheve
 
Innovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno AbiertoInnovación Ciudadana y Gobierno Abierto
Innovación Ciudadana y Gobierno Abierto
rafaecheve
 
Foro Gobierno Abierto Tabasco
Foro Gobierno Abierto TabascoForo Gobierno Abierto Tabasco
Foro Gobierno Abierto Tabasco
rafaecheve
 
Bitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO VillahermosaBitcoin Cash CANACO Villahermosa
Bitcoin Cash CANACO Villahermosa
rafaecheve
 
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
rafaecheve
 
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
rafaecheve
 
Innovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el EmprendimientoInnovacion Tecnológica para el Emprendimiento
Innovacion Tecnológica para el Emprendimiento
rafaecheve
 
Tu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y PersonalizaTu Primer Chatbot: Automatiza y Personaliza
Tu Primer Chatbot: Automatiza y Personaliza
rafaecheve
 
Desarrollando para la plataforma de Stellar
Desarrollando para la plataforma de StellarDesarrollando para la plataforma de Stellar
Desarrollando para la plataforma de Stellar
rafaecheve
 
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
rafaecheve
 
Herramientas para Emprender desde 0
Herramientas para Emprender desde 0Herramientas para Emprender desde 0
Herramientas para Emprender desde 0
rafaecheve
 
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
rafaecheve
 

Recently uploaded (20)

2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
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
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
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
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
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
 
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
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
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
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
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
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
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
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
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
 
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
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
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
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 

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