有人可以根据代表解释以下合成声明吗?

时间:2011-06-12 18:10:35

标签: iphone objective-c ios

我在接口文件中有以下代码:

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

用下划线合成是什么意思?我的意思是我知道常规合成的作用。一切正常,我在其他网站上查看了这个代码示例。

1 个答案:

答案 0 :(得分:0)

您的属性几乎总是有一个支持变量。什么

@synthesize delegate=_delegate;

确实声明搜索栏的支持变量将被称为_searchBar。这允许您将属性的名称与变量的名称分离。实际上,如果你不使用@synthesize,你根本不需要一个支持变量。

这可以:

  1. 避免与变量名冲突 和
  2. 在我使用时明确说明 局部变量,当我使用时 实例变量。