SlideShare uma empresa Scribd logo
1 de 37
LEARNING IOS
and hunting NSZombies in 3 weeks
About Me
                  @calvinchengx

• Chemical engineering from NUS
• Scientific Freezer Engineer for a local company
• Started my own software company, small team of 5 + some
interns
• Learned programming and web development along the way
• (web) appify scientific projects with universities
• Various consumer web apps python/django
• Attempted my own product start-up(s) including an app with
PhoneGap
• Currently working on an academic conference web app as a
product start-up, serving 3-4 conferences so far
3 weeks? Why so kan-cheong??

             :-)
“Teach yourself programming in Ten
       Years (10,000 hours)
         Peter Norvig, wrote in 2001
        http://norvig.com/21-days.html
“A little learning is a dangerous thing.
          Alexander Pope (1688 - 1744)
“Twas well observed by Lord Bacon, That a little
 knowledge is apt to puff up, and make men giddy,
but a great share of it will set them right, and bring
 them to low and humble thoughts of themselves.

             Anonymous, A B (16th century)
“Ars longa, vita brevis,
    occasio praeceps,
experimentum periculosm,
     iudicium difficile
     Hippocrates (c. 400 BC)
“To realize that you do not
 understand is virtue; Not to realize
that you do not understand is defect.
        Lao Tzu (c. 604 BC, Zhou Dynasty)
OK, OK, I GET IT!!! :-)
    So are you, Mr Calvin Cheng,
going to change the title of this talk???
NOT QUITE :-)
Evolutionary superiority triumphs Technical superiority

             Adopt a “Growth Mindset”
FIXED
You are great, or you aren’t


GROWTH
Anyone can master anything
WHY THIS MATTERS?
•   Split 10,000 hours into very small projects/parts-of-a-big-project
•   Push your boundary for each project and learn
•   Learning != Muscle Memory
•   Practice
Peter Norvig
                           tl;dr
•   Get interested
•   Program
•   Talk with other programmers
•   Work with other programmers
•   Work after other programmers
•   Learn at least 6 languages
•   Figure out computer instruction execution, disk, memory
•   Learn language standardization
•   Get out from language standardization
Getting started with iOS/Objective-C

• Read blog posts and books; download and play with iOS apps
• Program with Tutorials; and your own creations
• Talk with people on http://facebook.com/groups/iosdevscout
• Work with colleagues or hack-alongs @ iOS Dev Scout meet-ups
• Work after iOS open source libraries on http://github.com
• Learn at least Python, Javascript (jQuery), golang, C, clojure (etc)
• Understand pointers/memory management, multi-threading etc
• Read best practices, learn programming methodologies, XP,
TDD, CI, CD and practice UI/UX.

• Repeat
Key Concepts in Objective-C & iOS


• Superset of C
• Message passing (small talk/obj-c) versus Method calls (c/c++)
• Delegation versus Inheritance
Message Passing
      vs
Method Calling
• The difference between message passing and calling a
method is in the linking.

• c and c++ the function calls are linked at compile time
with the linker (except with virtual functions which
requires some runtime support).

• objective-c and smalltalk, you cannot guarantee what
functions will be run until runtime. The runtime
determines if an object actually implements the function
represented in the message. If it doesn't implement it, the
class will usually either forward the message onto another
object, or throw an exception.
• Overall, a message is the same thing as calling a
method directly, except the runtime finds the exact
function to be called instead of it being linked at compile
time.
Delegation


The real reason that you'd want to use delegation is that
the class you were designing has some resemblance to
another class, but isn't really enough like it that you'd call it
the same kind of thing.
Delegation


In c++, the only delegation that make sense is when you
are is a service (words ending with 'er', 'or', 'tory',
example HTMLLexER, JSONParsER, PrettyPrintER).

That is exactly what delegation sounds like. Delegating a
task to an expert class. (This could also result because the
lack of support for traits)

- Don Han
Delegation: An Example


Built-in iOS         Your Custom
  Object                Object




                    Be a Delegate!
                       (dance)
Delegation: An Example
@protocol CLLocationManagerDelegate<NSObject>                          Built-in iOS
@optional

/*
   * locationManager:didUpdateToLocation:fromLocation:
   *
   * Discussion:
   * Invoked when a new location is available. oldLocation may be nil if there is no previous location
   * available.
   */
- (void)locationManager:(CLLocationManager *)manager
	

 didUpdateToLocation:(CLLocation *)newLocation
	

 fromLocation:(CLLocation *)oldLocation;

...

@end
Delegation: An Example
                                                                  Our Custom
                                                                   class/object
// CurrentLocationViewController.h
// implements CLLocationManagerDelegate protocol
                                                                 (be a delegate!)
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface CurrentLocationViewController : UIViewController <CLLocationManagerDelegate>

....

@end
Delegation: An Example
#import "CurrentLocationViewController.h"
                                                                  Our Custom
                                                                   class/object
@interface CurrentLocationViewController ()
- (void)updateLabels;                                            (be a delegate!)
- (void)startLocationManager;
- (void)stopLocationManager;
- (void)configureGetButton;
- (NSString *)stringFromPlacemark:(CLPlacemark *)thePlacemark;
@end

@implementation CurrentLocationViewController {
 CLGeocoder *geocoder;
 CLPlacemark *placemark;
 BOOL performingReverseGeocoding;
 NSError *lastGeocodingError;

    CLLocationManager *locationManager;
    CLLocation *location;
    NSError *lastLocationError;
    BOOL updatingLocation;
}
Delegation: An Example
                                                                        Our Custom
                                                                         class/object
                                                                       (be a delegate!)
...

- (void)startLocationManager
{
   if ([CLLocationManager locationServicesEnabled]) {
       locationManager.delegate = self;
       locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
       [locationManager startUpdatingLocation];
       updatingLocation = YES;

          [self performSelector:@selector(didTimeOut:) withObject:nil afterDelay:60];
      }
}

...
Delegation: An Example
                                                                Our Custom
                                                                 class/object
                                                               (be a delegate!)
...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:
(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

{
      NSLog(@"didUpdateToLocation %@", newLocation);

      if ([newLocation.timestamp timeIntervalSinceNow] < -5.0) {
          return;
      }

      if (newLocation.horizontalAccuracy < 0) {
          return;

      }                               In CLLocationManagerDelegate.h
      // This is new
      CLLocationDistance distance = MAXFLOAT;
      if (location != nil) {
          distance = [newLocation distanceFromLocation:location];
      }

...
Delegation: An Example
                                                                    Built-in iOS
@protocol CLLocationManagerDelegate<NSObject>

@optional

/*
   * locationManager:didUpdateToLocation:fromLocation:
   *
   * Discussion:
   * Invoked when a new location is available. oldLocation may be nil if there is no
previous location
   * available.
   */
- (void)locationManager:(CLLocationManager *)manager
	

 didUpdateToLocation:(CLLocation *)newLocation
	

 fromLocation:(CLLocation *)oldLocation;
Takeaway:

Not much use cases for subclass-ing.

        Think in terms of
   composition & delegation to
  “specialized” pre-written code
Resources: iOS
• iOS Dev Scout
• iTunes University (Stanford, Paul Hegarty)
• Ray Wenderlich (Tutorials, Free & Paid)
•   https://github.com/calvinchengx/BullsEye
•   https://github.com/calvinchengx/Checklists
•   https://github.com/calvinchengx/Calculator
•   https://github.com/calvinchengx/MyLocations3
•   https://bitbucket.org/calvinchengx/foloup2
People I learn with/from




          many folks from......
Expand your programming perspectives. JOIN:

• iOS Dev Scout https://www.facebook.com/groups/iosdevscout/
• Pythonistas https://www.facebook.com/groups/pythonsg/
• PHP https://www.facebook.com/groups/sghypertextpreprocessors/
• Agile & DevOps https://www.facebook.com/groups/agiledevopssg/
• LittleHackers.com https://www.facebook.com/groups/littlehackers/
• golang SG https://www.facebook.com/groups/golanggonuts/
• RaspberryPi SG https://www.facebook.com/groups/
raspberrypisingapore/
Learning iOS and hunting NSZombies in 3 weeks

Mais conteúdo relacionado

Mais procurados

PresentationPatterns_v2
PresentationPatterns_v2PresentationPatterns_v2
PresentationPatterns_v2
Maksym Tolstik
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 

Mais procurados (20)

MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
PresentationPatterns_v2
PresentationPatterns_v2PresentationPatterns_v2
PresentationPatterns_v2
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
 
OOP, API Design and MVP
OOP, API Design and MVPOOP, API Design and MVP
OOP, API Design and MVP
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptReact Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 
iOS (7) Workshop
iOS (7) WorkshopiOS (7) Workshop
iOS (7) Workshop
 
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Solid OOPS
Solid OOPSSolid OOPS
Solid OOPS
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
MVS: An angular MVC
MVS: An angular MVCMVS: An angular MVC
MVS: An angular MVC
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
iOS viper presentation
iOS viper presentationiOS viper presentation
iOS viper presentation
 
React-Native Lecture 11: In App Storage
React-Native Lecture 11: In App StorageReact-Native Lecture 11: In App Storage
React-Native Lecture 11: In App Storage
 
Getting Started with Javascript
Getting Started with JavascriptGetting Started with Javascript
Getting Started with Javascript
 
Java Beans
Java BeansJava Beans
Java Beans
 

Semelhante a Learning iOS and hunting NSZombies in 3 weeks

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
Fabrizio Giudici
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
Shekhar Gulati
 

Semelhante a Learning iOS and hunting NSZombies in 3 weeks (20)

How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Aplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & JetpackAplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & Jetpack
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
COScheduler
COSchedulerCOScheduler
COScheduler
 
Cloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud WorkflowCloud Orchestration with RightScale Cloud Workflow
Cloud Orchestration with RightScale Cloud Workflow
 
Week3
Week3Week3
Week3
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in PracticeOpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
 

Mais de Calvin Cheng

Mais de Calvin Cheng (12)

FOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/Sovrin
FOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/SovrinFOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/Sovrin
FOSSASIA 2018 Self-Sovereign Identity with Hyperledger Indy/Sovrin
 
Hashgraph as Code
Hashgraph as CodeHashgraph as Code
Hashgraph as Code
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
iOS Beginners Lesson 4
iOS Beginners Lesson 4iOS Beginners Lesson 4
iOS Beginners Lesson 4
 
So, you want to build a Bluetooth Low Energy device?
So, you want to build a Bluetooth Low Energy device?So, you want to build a Bluetooth Low Energy device?
So, you want to build a Bluetooth Low Energy device?
 
Fabric
FabricFabric
Fabric
 
Ladypy 01
Ladypy 01Ladypy 01
Ladypy 01
 
zhng your vim
zhng your vimzhng your vim
zhng your vim
 
Django101 geodjango
Django101 geodjangoDjango101 geodjango
Django101 geodjango
 
Saving Gaia with GeoDjango
Saving Gaia with GeoDjangoSaving Gaia with GeoDjango
Saving Gaia with GeoDjango
 
Agile Apps with App Engine
Agile Apps with App EngineAgile Apps with App Engine
Agile Apps with App Engine
 

Último

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 

Learning iOS and hunting NSZombies in 3 weeks

  • 1. LEARNING IOS and hunting NSZombies in 3 weeks
  • 2. About Me @calvinchengx • Chemical engineering from NUS • Scientific Freezer Engineer for a local company • Started my own software company, small team of 5 + some interns • Learned programming and web development along the way • (web) appify scientific projects with universities • Various consumer web apps python/django • Attempted my own product start-up(s) including an app with PhoneGap • Currently working on an academic conference web app as a product start-up, serving 3-4 conferences so far
  • 3. 3 weeks? Why so kan-cheong?? :-)
  • 4. “Teach yourself programming in Ten Years (10,000 hours) Peter Norvig, wrote in 2001 http://norvig.com/21-days.html
  • 5. “A little learning is a dangerous thing. Alexander Pope (1688 - 1744)
  • 6. “Twas well observed by Lord Bacon, That a little knowledge is apt to puff up, and make men giddy, but a great share of it will set them right, and bring them to low and humble thoughts of themselves. Anonymous, A B (16th century)
  • 7. “Ars longa, vita brevis, occasio praeceps, experimentum periculosm, iudicium difficile Hippocrates (c. 400 BC)
  • 8. “To realize that you do not understand is virtue; Not to realize that you do not understand is defect. Lao Tzu (c. 604 BC, Zhou Dynasty)
  • 9. OK, OK, I GET IT!!! :-) So are you, Mr Calvin Cheng, going to change the title of this talk???
  • 10. NOT QUITE :-) Evolutionary superiority triumphs Technical superiority Adopt a “Growth Mindset”
  • 11. FIXED You are great, or you aren’t GROWTH Anyone can master anything
  • 12.
  • 13.
  • 14.
  • 15. WHY THIS MATTERS? • Split 10,000 hours into very small projects/parts-of-a-big-project • Push your boundary for each project and learn • Learning != Muscle Memory • Practice
  • 16. Peter Norvig tl;dr • Get interested • Program • Talk with other programmers • Work with other programmers • Work after other programmers • Learn at least 6 languages • Figure out computer instruction execution, disk, memory • Learn language standardization • Get out from language standardization
  • 17. Getting started with iOS/Objective-C • Read blog posts and books; download and play with iOS apps • Program with Tutorials; and your own creations • Talk with people on http://facebook.com/groups/iosdevscout • Work with colleagues or hack-alongs @ iOS Dev Scout meet-ups • Work after iOS open source libraries on http://github.com • Learn at least Python, Javascript (jQuery), golang, C, clojure (etc) • Understand pointers/memory management, multi-threading etc • Read best practices, learn programming methodologies, XP, TDD, CI, CD and practice UI/UX. • Repeat
  • 18. Key Concepts in Objective-C & iOS • Superset of C • Message passing (small talk/obj-c) versus Method calls (c/c++) • Delegation versus Inheritance
  • 19. Message Passing vs Method Calling
  • 20. • The difference between message passing and calling a method is in the linking. • c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). • objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn't implement it, the class will usually either forward the message onto another object, or throw an exception.
  • 21. • Overall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.
  • 22. Delegation The real reason that you'd want to use delegation is that the class you were designing has some resemblance to another class, but isn't really enough like it that you'd call it the same kind of thing.
  • 23. Delegation In c++, the only delegation that make sense is when you are is a service (words ending with 'er', 'or', 'tory', example HTMLLexER, JSONParsER, PrettyPrintER). That is exactly what delegation sounds like. Delegating a task to an expert class. (This could also result because the lack of support for traits) - Don Han
  • 24. Delegation: An Example Built-in iOS Your Custom Object Object Be a Delegate! (dance)
  • 25. Delegation: An Example @protocol CLLocationManagerDelegate<NSObject> Built-in iOS @optional /* * locationManager:didUpdateToLocation:fromLocation: * * Discussion: * Invoked when a new location is available. oldLocation may be nil if there is no previous location * available. */ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; ... @end
  • 26. Delegation: An Example Our Custom class/object // CurrentLocationViewController.h // implements CLLocationManagerDelegate protocol (be a delegate!) #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface CurrentLocationViewController : UIViewController <CLLocationManagerDelegate> .... @end
  • 27. Delegation: An Example #import "CurrentLocationViewController.h" Our Custom class/object @interface CurrentLocationViewController () - (void)updateLabels; (be a delegate!) - (void)startLocationManager; - (void)stopLocationManager; - (void)configureGetButton; - (NSString *)stringFromPlacemark:(CLPlacemark *)thePlacemark; @end @implementation CurrentLocationViewController { CLGeocoder *geocoder; CLPlacemark *placemark; BOOL performingReverseGeocoding; NSError *lastGeocodingError; CLLocationManager *locationManager; CLLocation *location; NSError *lastLocationError; BOOL updatingLocation; }
  • 28. Delegation: An Example Our Custom class/object (be a delegate!) ... - (void)startLocationManager { if ([CLLocationManager locationServicesEnabled]) { locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; [locationManager startUpdatingLocation]; updatingLocation = YES; [self performSelector:@selector(didTimeOut:) withObject:nil afterDelay:60]; } } ...
  • 29. Delegation: An Example Our Custom class/object (be a delegate!) ... - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"didUpdateToLocation %@", newLocation); if ([newLocation.timestamp timeIntervalSinceNow] < -5.0) { return; } if (newLocation.horizontalAccuracy < 0) { return; } In CLLocationManagerDelegate.h // This is new CLLocationDistance distance = MAXFLOAT; if (location != nil) { distance = [newLocation distanceFromLocation:location]; } ...
  • 30. Delegation: An Example Built-in iOS @protocol CLLocationManagerDelegate<NSObject> @optional /* * locationManager:didUpdateToLocation:fromLocation: * * Discussion: * Invoked when a new location is available. oldLocation may be nil if there is no previous location * available. */ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
  • 31. Takeaway: Not much use cases for subclass-ing. Think in terms of composition & delegation to “specialized” pre-written code
  • 32. Resources: iOS • iOS Dev Scout • iTunes University (Stanford, Paul Hegarty) • Ray Wenderlich (Tutorials, Free & Paid) • https://github.com/calvinchengx/BullsEye • https://github.com/calvinchengx/Checklists • https://github.com/calvinchengx/Calculator • https://github.com/calvinchengx/MyLocations3 • https://bitbucket.org/calvinchengx/foloup2
  • 33. People I learn with/from many folks from......
  • 34.
  • 35.
  • 36. Expand your programming perspectives. JOIN: • iOS Dev Scout https://www.facebook.com/groups/iosdevscout/ • Pythonistas https://www.facebook.com/groups/pythonsg/ • PHP https://www.facebook.com/groups/sghypertextpreprocessors/ • Agile & DevOps https://www.facebook.com/groups/agiledevopssg/ • LittleHackers.com https://www.facebook.com/groups/littlehackers/ • golang SG https://www.facebook.com/groups/golanggonuts/ • RaspberryPi SG https://www.facebook.com/groups/ raspberrypisingapore/

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. A small amount of knowledge can mislead people into thinking that they are more expert than they really are. The &amp;#x201C;learning version&amp;#x201D;.\n
  6. A B, predating Alexander Pope, the &amp;#x201C;Knowledge version&amp;#x201D;.\n
  7. Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgment difficult.\n
  8. \n
  9. \n
  10. \n
  11. \n
  12. Growth mindset\n
  13. Growth mindset\n
  14. \n
  15. In the video, Derek Sivers talk about a study where 2 classes are conducted in 2 different manners.\n\nMany small claypots (quantity-and-practice focused) versus Make 1 good claypot (quality-and-single-grade-approach).\n
  16. \n
  17. \n
  18. http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn&apos;t implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you&apos;d done that with subclassing, you&apos;d have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear.\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
  19. http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn&apos;t implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you&apos;d done that with subclassing, you&apos;d have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
  20. http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn&apos;t implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you&apos;d done that with subclassing, you&apos;d have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
  21. http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn&apos;t implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you&apos;d done that with subclassing, you&apos;d have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
  22. http://stackoverflow.com/questions/5451926/is-message-passing-in-small-talk-and-objectivec-same-as-calling-method-with-valuOnce the actual function call is made, there is no difference. The difference between message passing and calling a method is in the linking. For languages like c and c++ the function calls are linked at compile time with the linker (except with virtual functions which requires some runtime support). With languages that use a messaging system like objective-c and smalltalk, you cannot guarantee what functions will be run until runtime. The runtime determines if an object actually implements the function represented in the message. If it doesn&apos;t implement it, the class will usually either forward the message onto another object, or throw an exception. However, if the class does implement it, the runtime determines the address of the actual function, and calls it in the exact same manner as c (pushing the arguments and the return address onto the stack).\nOverall, a message is the same thing as calling a method directly, except the runtime finds the exact function to be called instead of it being linked at compile time.\nhttp://stackoverflow.com/questions/2068158/why-does-cocoa-use-delegates-rather-than-inheritance\nWith delegates, you can have one object be the delegate of many other objects. For example, you can have your MyController instance be the delegate of an NSTableView, an NSTextField, an NSWindow, and any other objects that compose your interface. This gives a compact place to put all of your user interface code related to one section of your UI.\nIf you&apos;d done that with subclassing, you&apos;d have to create one subclass every object you wanted callbacks from.\nNot only does delegation in C++ and Java mean writing more code, it is also not as performant as class inheritance. Implicit delegation by inheritance needs constant time, explicit delegation is linear. http://stackoverflow.com/questions/1209943/java-equivalent-of-cocoa-delegates-objective-c-informal-protocols?rq=1\n\nIn Python (and of course Objective-C), delegation can be achieved with as little as one extra method to delegate to one or more classes. Altering the number of parameters of a delegated method often requires a change to only one module.\n\n
  23. Don Han.\n\n
  24. A protocol is essentially a group of functions/methods.\n\nA class that extends itself with the protocol promises to implement the methods in the protocol (optional or required).\n
  25. Pre-written protocol called &amp;#x201C;CLLocationManagerDelegate&amp;#x201D; that we can use in our custom code.\n
  26. How do we use it? Our UIViewController extends itself with all the Core Location functionalities pre-written in CLLocationManagerDelegate!\n
  27. In our corresponding implementation file, we can use the methods declared in the CLLocationManagerDelegate!\n
  28. Open Xcode and show everything else\n
  29. \n
  30. (As seen earlier)\n
  31. This makes a lot of sense because we are essentially reusing a lot of established code already given to us by Apple&amp;#x2019;s Cocoa Touch framework in various blablaDelegate.h files.\n
  32. \n
  33. \n
  34. A parting message. What? Did I just contradict myself again?\n
  35. Not really... &amp;#x201C;Be water, my friend&amp;#x201D;\n
  36. \n
  37. \n