LLVM 3.0 编译器好的特性

在MainViewController.h, 你会发现这个类有两个实例变量:

#import <UIKit/UIKit.h> 
@interface MainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{ 
     NSOperationQueue *queue; 
     NSMutableString *currentStringValue; 
}
@property (nonatomic, retain) IBOutlet UITableView *tableView; 
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar; 
@end

一个类公开的接口中,不是放实例变量的一个好地方。通常,实例变量是你类内部的一部分,不是你想暴露给公共接口的。 对你这个类的用户来说, 知道它的实例变量不是那么重要。 从数据隐藏的角度来看, 如果我们能将这些实现放到这个类的 @implementation 部分中才是更好。 

我很高兴的告诉你,现在在 LLVM 3.0 编译器中,这个是可以实现的。

从 MainViewController.h 中删除实例变量块, 把他们放到 MainViewController.m 中。 这个头文件看起来应该是这样:

#import <UIKit/UIKit.h> 
@interface MainViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> 
 
@property (nonatomic, retain) IBOutlet UITableView *tableView; 
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar; 

@end

MainViewController.m 的顶部看起来应该是这样:

@implementation MainViewController
{
     NSOperationQueue *queue;
 
     NSMutableString *currentStringValue; 
}

构建应用。。。 它能正常工作。 这让 .h 文件更加清晰。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值