Learning iOS and hunting NSZombies in 3 weeks
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Learning iOS and hunting NSZombies in 3 weeks

  • 991 views
Uploaded on

Language (programming language) wars are overrated. ...

Language (programming language) wars are overrated.

As a professional/career software engineer, it is our job to learn fast, evolve and continually grow in the context of different languages and software paradigms.

Learning Objective-C and iOS cocoa touch framework isn't as scary as people purport it to be. Ignore the critics, trust in your own abilities and dive into Objective-C if you need to build a mobile app for your company. Today.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
991
On Slideshare
722
From Embeds
269
Number of Embeds
9

Actions

Shares
Downloads
17
Comments
1
Likes
0

Embeds 269

http://geekcamp.sg 222
http://localhost 28
http://www.geekcamp.sg 7
http://us-mg6.mail.yahoo.com 5
http://www.linkedin.com 3
http://admin 1
http://bl174w.blu174.mail.live.com 1
http://www.verious.com 1
http://www.techgig.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • A small amount of knowledge can mislead people into thinking that they are more expert than they really are. The “learning version”.\n
  • A B, predating Alexander Pope, the “Knowledge version”.\n
  • Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgment difficult.\n
  • \n
  • \n
  • \n
  • \n
  • Growth mindset\n
  • Growth mindset\n
  • \n
  • 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
  • \n
  • \n
  • 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'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'd done that with subclassing, you'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
  • 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'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'd done that with subclassing, you'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
  • 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'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'd done that with subclassing, you'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
  • 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'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'd done that with subclassing, you'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
  • 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'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'd done that with subclassing, you'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
  • Don Han.\n\n
  • 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
  • Pre-written protocol called “CLLocationManagerDelegate” that we can use in our custom code.\n
  • How do we use it? Our UIViewController extends itself with all the Core Location functionalities pre-written in CLLocationManagerDelegate!\n
  • In our corresponding implementation file, we can use the methods declared in the CLLocationManagerDelegate!\n
  • Open Xcode and show everything else\n
  • \n
  • (As seen earlier)\n
  • This makes a lot of sense because we are essentially reusing a lot of established code already given to us by Apple’s Cocoa Touch framework in various blablaDelegate.h files.\n
  • \n
  • \n
  • A parting message. What? Did I just contradict myself again?\n
  • Not really... “Be water, my friend”\n
  • \n
  • \n

Transcript

  • 1. LEARNING IOSand 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 + someinterns• 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 withPhoneGap• Currently working on an academic conference web app as aproduct 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 realizethat 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. FIXEDYou are great, or you aren’tGROWTHAnyone can master anything
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. Key Concepts in Objective-C & iOS• Superset of C• Message passing (small talk/obj-c) versus Method calls (c/c++)• Delegation versus Inheritance
  • 16. Message Passing vsMethod Calling
  • 17. • The difference between message passing and calling amethod is in the linking.• c and c++ the function calls are linked at compile timewith the linker (except with virtual functions whichrequires some runtime support).• objective-c and smalltalk, you cannot guarantee whatfunctions will be run until runtime. The runtimedetermines if an object actually implements the functionrepresented in the message. If it doesnt implement it, theclass will usually either forward the message onto anotherobject, or throw an exception.
  • 18. • Overall, a message is the same thing as calling amethod directly, except the runtime finds the exactfunction to be called instead of it being linked at compiletime.
  • 19. DelegationThe real reason that youd want to use delegation is thatthe class you were designing has some resemblance toanother class, but isnt really enough like it that youd call itthe same kind of thing.
  • 20. DelegationIn c++, the only delegation that make sense is when youare is a service (words ending with er, or, tory,example HTMLLexER, JSONParsER, PrettyPrintER).That is exactly what delegation sounds like. Delegating atask to an expert class. (This could also result because thelack of support for traits)- Don Han
  • 21. Delegation: An ExampleBuilt-in iOS Your Custom Object Object Be a Delegate! (dance)
  • 22. 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
  • 23. 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
  • 24. 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;}
  • 25. 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]; }}...
  • 26. 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]; }...
  • 27. 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 noprevious location * available. */- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
  • 28. Takeaway:Not much use cases for subclass-ing. Think in terms of composition & delegation to “specialized” pre-written code
  • 29. 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
  • 30. People I learn with/from many folks from......
  • 31. 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/