Re: [問題]請教 Objective-C 的語法
※ 引述《copyshaft (冒煙的洋蔥)》之銘言:
: 版上的朋友大家好:
: 今天在研究一個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是一個物件,這個宣告的 <> 讓我困惑)
有一個protocol 名字也叫NSObject
: 2.
: id <MBBrotViewDelegate> delegate;
: 這個宣告,它的意思是是否是說delegate這個物件使用
: MBBrotViewDelegate這個protocol
delegate這個變數,需要一個有實作<MBBrotViewDelegate> protocol的物件
id 代表不管任何型別只要有實作<MBBrotViewDelegate>的method就可以了
如果非要給型別的話
NSView <MBBrotViewDelegate> * delegate;
代表一定要有一個NSView * 的物件,也實作<MBBrotViewDelegate>
: 等同以下的宣告???
: @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: 219.85.163.134
推
06/04 20:00, , 1F
06/04 20:00, 1F
推
06/04 21:11, , 2F
06/04 21:11, 2F
→
06/04 21:11, , 3F
06/04 21:11, 3F
→
06/04 21:45, , 4F
06/04 21:45, 4F
→
06/04 21:46, , 5F
06/04 21:46, 5F
→
06/04 23:01, , 6F
06/04 23:01, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):