2013-05-29 34 views
0

我发现平时委托模式的一个微小变异:括号中的id <ProtocolDelegate>:为什么不使用typedef?

我的协议是在一些Protocol.h定义,即

@protocol ProtocolDelegate <NSObject> 
//… 
@end 

//The variant, see below 
typedef NSObject <ProtocolDelegate> Delegate; 

接下来,我ViewController.h

@interface: UIViewController 
@property (nonatomic, strong) Delegate*delegateOfviewController; 
//… 
@end 

然后,在我ViewController.m

@implementation ViewController 
@synthesize delegateOfviewController; 
//… 
@end 

最后,在我的AppDelegate.m

//… 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
//… 
self.ViewController.delegateOfviewController = self; 
//… 
[self.window makeKeyAndVisible]; 
return YES; 
} 

而且一切都很顺利。它真的等同于“id委托”的常用方式,还是你认为应该避免使用这样的typedef?

谢谢!

jgapc

回答

0

唯一的区别应该是您是否使用指针符号。我不相信有什么区别,但是为什么在Objective-C给你id时做一个typedef?

相关问题