通常の委任パターンの小さな変形を見つけました。
私のプロトコルは、いくつかの 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 delegate」と同等ですか、それともそのような typedef は避けるべきだと思いますか?
ありがとう!
jgapc