Opened 11 years ago
Last modified 7 years ago
#453 new enhancement
Need a way to declare that Objective-C classes implement formal protocols
Reported by: | rme | Owned by: | rme |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Objective-C Bridge | Version: | trunk |
Keywords: | Cc: |
Description
There's currently no way to say the equivalent of
@interface MyTextView : NSObject < NSTextInput > { ... }
using DEFCLASS.
Perhaps adding an additional class option, e.g.
(defclass some-objc-class (ns:ns-object) ((slot1 :accessor slot1 :foreign-type :id)) (:metaclass ns:+ns-object) (:objc-protocols #>NSTextInput))
would be a decent way to do it.
Adding a protocol to a class seems to be straightforward with Apple's new runtime (there's a function called class_addProtocol). The old runtime doesn't provide anything so convenient.
A workaround is to override #/conformsToProtocol: in the class that implements the protocol, e.g., something like
(objc:defmethod (#/conformsToProtocol: #>BOOL) ((self my-text-view) protocol) (#/conformsTo: protocol (@protocol "NSTextInput")))
Note: See
TracTickets for help on using
tickets.
(In [15476]) Crude support for declaring that Objective-C classes implement formal protocols.
Example:
(defclass some-objc-class (ns:ns-object)
See ticket:453.