Strong Like Bull
Strong Like Bull

Reputation: 11317

Explanation of the synthesize statement in terms of delegates?

I have the following code in the interface file:

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
@class FaxRecipient;

//Definition of the delegate's interface
@protocol AddLocalRecipientsTableViewControllerDelegate
-(void)getLocalRecipient:(FaxRecipient*)recipient;
@end

@interface AddLocalRecipientsTableViewController : UITableViewController {
    NSMutableArray *localRecipientItems;
    NSURLConnection *connectionInprogress;
    UIActivityIndicatorView *activityIndicator;
    NSIndexPath *lastIndexPath;
    FaxRecipient * faxRecipient;
}

@property(nonatomic,retain) NSIndexPath *lastIndexPath;
@property(nonatomic,retain)FaxRecipient * faxRecipient;
@property (nonatomic, assign) id<AddLocalRecipientsTableViewControllerDelegate> delegate;


-(void) loadLocalRecipients;

I have the following line in my implementation file:

@synthesize delegate=_delegate;

What does the synthesize with the underscore mean? I mean I know what a regular synthesize does. Everything works OK and I looked at this code example at some other site.

Upvotes: 0

Views: 268

Answers (1)

Julio Gorg&#233;
Julio Gorg&#233;

Reputation: 10106

Your properties almost always have a backing variable. What

@synthesize delegate=_delegate;

does is declare that the backing variable for your search bar will be called _searchBar. This allows you to decouple the name of the property from the name of your variable. In fact, if you don't use @synthesize you don't need to have a backing variable at all.

This can:

  1. avoid clashes with variable names and
  2. make it clear when I'm using a local variable and when I'm using an instance variable.

Upvotes: 0

Related Questions