作者copyshaft (冒烟的洋葱)
看板MacDev
标题[问题]请教 Objective-C 的语法
时间Fri Jun 4 15:13:16 2010
版上的朋友大家好:
今天在研究一个Sample project看到了以下的语法,
#import <Cocoa/Cocoa.h>
@protocol MBBrotViewDelegate <NSObject>
-(void)mouseDownAtPoint:(NSPoint)point;
@end
@interface MBBrotView : NSView {
id <MBBrotViewDelegate> delegate;
BOOL mouseIsDown;
}
@property id <MBBrotViewDelegate> delegate;
@end
想请教各位的问题如下:
1.
@protocol MBBrotViewDelegate <NSObject>
是指後续使用MBBrotViewDelegate这个protocol的物件还要
implement NSObject这个protocol??
(我的了解是NSObject是一个物件,这个宣告的 <> 让我困惑)
2.
id <MBBrotViewDelegate> delegate;
这个宣告,它的意思是是否是说delegate这个物件使用
MBBrotViewDelegate这个protocol
等同以下的宣告???
@interface delegate : NSObject <MBBrotViewDelegate>
{}
@end
二 语法片段2:
[[NSNotificationCenter defaultCenter]
addObserverForName:NSApplicationDidFinishLaunchingNotification
object:nil queue:nil
usingBlock:^(NSNotification *notif) {
currentImageLayer.frame = NSRectToCGRect(brotView.bounds);
[brotView.layer addSublayer:currentImageLayer];
}];
在下是第一次看到 ^(NSNotification *notif) {}
直觉很像 pointer of function
查阅官方文件(NSNotificationCenter)也没看到usingBlock的相关资讯
不知版上是否有前辈能大略说明一下 ^() 的用途
在下资质驽顿还望版上前辈能不吝指教,谢谢。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.204.186.221
※ 编辑: copyshaft 来自: 123.204.186.221 (06/04 15:18)