Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

A presentation given at MobileDevNJ about Delegation patterns on the iOS platform.

Published in: Technology
  • Be the first to comment

  • Be the first to like this


  1. 1. Delegation Object Messaging
  2. 2. What is Delegation?Delegation is a design pattern in object-orientedprogramming where an object, instead ofperforming one of its stated tasks, delegates thattask to an associated helper object. It passes thebuck, so to speak (technically, an Inversion ofResponsibility).The helper object is called the delegate. (source:Wikepedia)
  3. 3. Examples: AppDelegate• UIApplicationDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions - (void)applicationWillTerminate: (UIApplication *)application
  4. 4. Examples: UITableView• UITableViewDelegate - UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - ...tableView:didDeselectRowAtIndexPath:
  5. 5. What Problem Does Delegation Solve? Object A Object B
  6. 6. Write to File Object A Object B (Equipment) (User Interface) somefile.txt
  7. 7. Define Pointers Object A Object B (Equipment) (User Interface)ObjectB *myObject;myObject = [self getSomeData:data];
  8. 8. App Delegate Define Property Object A Object B (Equipment) (User Interface)AppDelegate *d = [[UIApplication sharedApplication] delegate];d.someString = ...
  9. 9. App Delegate Define Delegate Object A Object B (Equipment) (User Interface)• Create Delegate Object • Helper App• Defines Protocols • Delegate of Object A - List of methods • Implements Protocol
  10. 10. Demo• Build a Program using Delegation