That illustrates the general approach. You make a category on NSObject that declares the names of your callback methods. NSObject doesn't actually implement these methods. This type of category is called an informal protocol, you're just saying that many objects might implement these methods. They're a way to forward declare the type signature of the selector.
接下来,您有一些对象是“ MyClass”的委托,并且 MyClass 根据需要调用委托的委托方法。如果您的委托回调是可选的,那么您通常会使用类似于“ If ([ committee response dsToSelector:@selector (myClassWillDoSomething:)){”的内容在分派站点上保护它们。在我的示例中,需要委托来实现这两个方法。
您也可以使用@protocol 定义的正式协议来代替非正式协议。如果你这样做,你会改变委托设置实例变量的类型,并将其设置为“ id <MyClassDelegate>”而不仅仅是“ id”。