0

通常の委任パターンの小さな変形を見つけました。

私のプロトコルは、いくつかの 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

4

1 に答える 1

0

唯一の違いは、ポインター記号を使用するかどうかです。違いはないと思いますが、Objective-C が ID を与えるのに typedef を作成するのはなぜですか?

于 2013-05-29T03:34:29.637 に答える