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