2011-06-12 17 views
0

我在接口文件下面的代碼:有人可以根據代表解釋下面的合成聲明嗎?

#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; 

我在執行文件中的以下行:

@synthesize delegate=_delegate; 

什麼用下劃線的合成是什麼意思?我的意思是我知道常規合成的功能。一切正常,我在其他站點查看了這個代碼示例。

+3

許多可能的重複。 http://stackoverflow.com/search?q=objc+property+underscore。 – csano 2011-06-12 18:14:19

+0

可能重複[@synthesize window = _window做什麼?](http://stackoverflow.com/questions/5170631/what-does-synthesize-window-window-do) – 2011-06-12 18:15:54

回答

0

你的屬性幾乎總是有一個後備變量。什麼

@synthesize delegate=_delegate; 

是聲明您的搜索欄的支持變量將被稱爲_searchBar。這使您可以將屬性的名稱與變量的名稱分開。事實上,如果你不使用@synthesize,你根本不需要有一個支持變量。

這可以:

  1. 變量名 和
  2. 避免衝突,使之清楚,當我使用的是 局部變量,當我使用的是 實例變量。
相關問題