I'm writing a Cocoa API for a project and the API takes a delegate. The protocol that I came up with declares all the methods as optional, but why would I do that instead of just documenting the delegate methods in a header file and taking a plain id as a parameter?
相关问题
- Image loads in simulator but not device?
- Pass code to a method as an argument
- NSOutlineView drag line stuck + blue border
- Get the result of Func<object> when object i
- How to set delegate in a protocol extension
相关文章
- Xcode: Is there a way to change line spacing (UI L
- Converting (u)int64_t to NSNumbers
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- “getter” keyword in @property declaration in Objec
- How to get a CGImageRef from Context-Drawn Images?
- NSMenuItem KeyEquivalent “ ”(space) bug
- Why are my UIView layer properties not being set w
- create UIImageView
Because having "all of these methods" optional isn't quite the same as permitting "anything you care to send".
It also produces code that is more usable in the IDE. For example if I'm looking at
I can command+double click in Xcode to jump to the definition of FooBarDelegate. With a category there's no formal declaration of intent to be a delegate.
Also, @required can be a problem for future plans with regard to backward binary compatibility and a new preferred method signature.
For the benefit of your users. If the object takes delegates conforming to some protocol and they pass something else in, the compiler can tell them. That isn't possible if you take an id and use a category as the delegate method interface.