[問題]請教 Objective-C 的語法
版上的朋友大家好:
今天在研究一個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)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章