Im trying to use this method: class_addMethod()
which in Obj-c is used like this:
class_addMethod([self class], @selector(eventHandler), imp_implementationWithBlock(handler), "v@:");
And Im using it like this in Swift:
class_addMethod(NSClassFromString("UIBarButtonItem"), "handler", imp_implementationWithBlock(handler), "v@:")
It is an extension for UIBarButtonItem
as you might have figured out.
imp_implementationWithBlock
takes a parameter of type AnyObject!
How can I cast ()->()
into AnyObject
?
I've tried to cast it like this: handler as AnyObject
but it gives me an error saying: ()->() does not conform to protocol 'AnyObject'
reinterpretCast()
? – Omura