Open AshwinDamji opened 8 years ago
I'm having the same issue, some answers ?
something like
let block: @convention(block) (NSString!) -> Void = {
(string: NSString!) -> Void in
print(string)
}
label.enableStringDetection("test string", withAttributes: [NSForegroundColorAttributeName: UIColor.redColor(), RLTapResponderAttributeName: unsafeBitCast(block, AnyObject.self)])
seems to do the trick
@vcambur Thanks
Worked for me.
Shorten version of @vcambur is:
extension NSAttributedString.Key {
static var tap: String {
return RLTapResponderAttributeName
}
}
func Tap(responder: @escaping (String) -> Void) -> AnyObject {
let block: @convention(block) (NSString!) -> Void = {
(string: NSString!) -> Void in
responder(string as String)
}
return unsafeBitCast(block, to: AnyObject.self)
}
usage:
label.enableStringDetection("test string", withAttributes: [
NSAttributedString.Key.tap: Tap { text in
print(text)
},
])
Hi,
I am using Swift 2.0 I have written below code.
The above bold line gives following error: Value of type 'PatternTapResponder' (aka 'ImplicitlyUnwrappedOptional -> ()') does not conform to expected dictionary value type 'AnyObject'
And also when I write
into dictionary below errors occur at runtime.
Could not cast value of type 'Swift.ImplicitlyUnwrappedOptional -> ()' (0x11d334080) to 'Swift.AnyObject' (0x11be6c018)