Thursday, 15 January 2015

ios - How do I pass in a void block to objc_setAssociatedObject in swift -


I am trying to add tap gesture support to UIView via an extension. This pretty straight forward Objective-C is using, but I am trying to set the following error when setting zero return blocks on the order property.

Error: Type '() -> zero' does not correspond to 'AnyObject' for the protocol

Here is the property calculated:

  on tapAction: (() - & Gt; zero)? Set {{Objc_getAssociatedObject (self, and Associated Keys, SGL ActionHandler Tapblok}} {objc_setAssociatedObject (self, and Associated Keys. SNGLSonHandlerTapBlock, New Vale, UIINT (OBJC_ASSOCIION_CAP_NANOTOOM))}}  

I tried Is to install tapAction as a typealias , but still receive the same error.

itemprop = "text">

The problem is that the objects are closed> code> anyObject

You can look at wrapping off in a class together and the single asset is something like this:

  class closurer {var close: (() -> zero)? Init (_closed: (-) -> zero)? Tapaction {{self.closure = off}} on: ((- - -> nil)? {Get if if cl = objc_getAssociatedObject (self, "key")? ClosureWrapper {return cl.closure} return zero} set {objc_setAssociatedObject (self, "key", ClosureWrapper (newValue), uint (OBJC_ASSOCIATION_RETAIN_NONATOMIC)}}}  

It is a bit ugly and using A good TypLaas but there is a way to do this.


No comments:

Post a Comment