当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - What NSTextFieldDelegate trully is?

问题描述:

The declaration of NSTextFieldDelegate really confuse me a lot.

In Xcode, I click "jump to defination" of NSTextFieldDelegate, and found:

@protocol NSTextFieldDelegate <NSControlTextEditingDelegate> @end

I have known that if we add a <...> syntax after a NSObject type (such as "id") declaration, that means this object comforms to the protocol specified in "<>".

However, books of Obj-C I have do not mentioned what it means when the "<>" means when it follows a protocol declaration...

So, Question 1: What does "<>" means when it is after a declaration of protocol?


I continued look into the NSControlTextEditingDelegate, and found several methods begin with "control:...". But what attracted me most was the text above the NSControlTextEditingDelegate defination:

@interface NSObject(NSControlSubclassNotifications)

- (void)controlTextDidBeginEditing:(NSNotification *)obj;

- (void)controlTextDidEndEditing:(NSNotification *)obj;

- (void)controlTextDidChange:(NSNotification *)obj;

@end

Oh, here comes new questions:

Question 2: What is the syntex "NSObject(NSControlSubclassNotifications)" means? What is NSControlSubclassNotifications actually?

Quesiont 3: What are the relationships among NSObject, NSControlSubclassNotifications and NSControlTextEditingDelegate? The apple doc simply says: "The NSTextFieldDelegate protocol adopts the NSControlTextEditingDelegate protocol and currently does not extend it further." But I could not understand its meaning...

网友答案:
  1. It means that the protocol conforms to ("adopts") another protocol, so basically the protocol contains all the methods in both protocols. It's somewhat similar to subclassing.
  2. It's a category, in this case used as an informal protocol. It fulfills pretty much the same purpose as a (formal) protocol here (though that's just one use case of categories), you'll mostly see this style in older APIs.
  3. NSControlSubclassNotification is a category on NSObject. It basically adds new methods to all classes that inherit from NSObject. NSTextFieldDelegate is effectively the same as NSControlTextEditingDelegate, just with a different name, but it's possible that new methods might be added to it in the future that are unrelated to NSControlTextEditingDelegate, so that's probably why it's designed as a separate protocol.
分享给朋友:
您可能感兴趣的文章:
随机阅读: