Successfully reported this slideshow.

Beginning iPhone Development

1

Share

Upcoming SlideShare
Cocoa Design Patterns
Cocoa Design Patterns
Loading in …3
×
1 of 11
1 of 11

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

Beginning iPhone Development

  1. 1. An Introduction iPhone Programming Stewart Gleadow, Thoughtworks
  2. 2. Barriers to Entry • Objective C • I can’t see my code for all the square brackets • Development Tools • I survived XCode and lived to tell the tale • Real Software? • Only people that don’t know how to program write iPhone Apps?
  3. 3. Learning the Hard Way • Memory Model • Get your memory management right the first time • Frameworks • Don’t fight the framework • View Lifecycles
  4. 4. User Interfaces • Interface Builder • Hand-rolled Controllers • NavigationController, TabController • UIViewController subclasses • UIView subclasses
  5. 5. Testing • Unit Testing • OCUnit, GTM Test, GHUnit • OCMock • Not on the iPhone? • Functional Testing • Instruments & UIAutomation • Manual Testing
  6. 6. iPhone Concerns • Persistence • Performance • Multiple Resolutions • Network Dropouts
  7. 7. Header @class ExtraClass; @interface SomeClass : NSObject { ExtraClass *extraClass_; } + (NSString *)classLevelMethod; - (id)initWithExtraClass:(ExtraClass *)extraClass; @property (nonatomic, retain) ExtraClass *extraClass; @end
  8. 8. Implementation #import “SomeClass.h” #import “ExtraClass.h” @interface SomeClass () @end @implementation SomeClass - (id)initWithExtraClass:(ExtraClass *)extraClass; { if (self = [super init]) { [self setExtraClass:extraClass]; } return self; } -(void)dealloc; { [extraClass_ release]; } @synthesize extraClass = extraClass_; @end
  9. 9. Using your Class ExtraClass *extraClass = [ExtraClass defaultExtraClass]; SomeClass *someClass = [[SomeClass alloc] initWithExtraClass:extraClass]; // do some stuff with your class ExtraClass *fromAccessor = [someClass extraClass]; [someClass release]; someClass = nil;
  10. 10. Looking Forward • Barriers to entry are more like hurdles • Objective C is not as bad as I thought • XCode 4 to save the day? • Don’t give up on testing
  11. 11. Demo

Editor's Notes

  • \n
  • - Barriers to entry:\nObjective C: not a pretty language, message passing, small talk\n- semi-dynamic (responds to, contexts, monkey patching)\n- header files & properties\nDevelopment Tools: developers are second class citizens, testing difficult, TDD/Agile, refactoring\n- get to know the tools\nHobby only: reflected in developer tools, not going for corporate market, no pressure to learn it\n
  • - Objective C 2 autorelease pool (now available on iPhone)\n- memory leaks are much easier to avoid than they are to track down\n- follow conventions for autorelease/retain\n- frameworks: UIKit, CoreGraphics, CoreAnimation, CoreData, Three20/Facebook\n- view lifecycles: - when views are created and destroyed\n- low memory conditions\n- make sure your delegates are still there\n
  • IB - drag and drop\n - probably ok if you’re using the framework exactly as intended\nhand-roller controllers\n- safer option if you want control\n
  • OCUnit, GTM Test (Google Toolbox for Mac)\nGHUnit - can be used with both testing frameworks\n- run unit tests on the device\nOCMock - instance methods only, swizzle for static methods\nInstruments - with XCode 3.2.3 or so, iPad version (on device in iPhone 4)\nUIAutomation - Javascript hooks, device or phone, Jasmine (RSpec/ScrewUnit-like)\nManual Tests - document reproducible steps (Gherkin-like syntax)\n
  • Really for any mobile platform\nPersistence - application lifecycle (multitasking without multitasking)\n- good for users, bad for developers\n- needs to keep track of your state all the time\nPerformance - multiple devices to test on\n- must do device testing (simulator has a lot more resources)\nResolutions - \nDropouts - anyc requests, what to do?\n
  • forward class definition\ntrailing underscore to not clash with frameworks\n+ for class level methods, - for instance level\n\nnonatomic guarantees the whole value is received or set, not thread safety\nOther Property Types:\ncopy - when mutable subclasses\nassign - for primitive types, and delegates\n
  • import - like include with a #ifdef guard for multiple inclusion\nprivate parts in “anonymous” categories, no extra attributes\n(doesn’t mean people can’t use the private methods)\nanonymous vs named categories\n; on methods so the same as header, for copy and paste (not here)\nsuper - needs to be called (returns self, does not set it, so assign)\nuse properties with messaging not . syntax so not confused with C structs\n
  • Call class method on extra class, convention means this is autoreleased\n- anything that wants to keep it needs to call retain, or it will get cleaned up\nrelease any objects that are\nnil - can pass it messages, it just does nothing (clean and readable not equivalent)\n
  • Objective C is not too bad\n- long lines, lots of brackets, after a while see bbrh\n- code actually reads quite nicely\nXCode 4 looks a lot better\nTesting - don’t revert back to old habits\n- new platform, don’t know use in advance, test after?\n
  • \n
  • ×