Opened 11 years ago

Last modified 8 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:


There's currently no way to say the equivalent of

@interface MyTextView : NSObject < NSTextInput >


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")))

Change History (1)

comment:1 Changed 8 years ago by rme

(In [15476]) Crude support for declaring that Objective-C classes implement formal protocols.


(defclass some-objc-class (ns:ns-object)

((slot1 :accessor slot1 :foreign-type :id)) (:metaclass ns:+ns-object) (:objc-protocols "NSTextInput" "NSCopying"))

See ticket:453.

Note: See TracTickets for help on using tickets.