I am using a library MDWamp written in objective C and it has a property of the following type
@property (nonatomic, strong) void (^deferredWampCRASigningBlock)( NSString *challange, void(^finishBLock)(NSString *signature) );
This is the signature in swift
public var deferredWampCRASigningBlock: ((String!, ((String!) -> Void)!) -> Void)!
and when I try to instantiate it in swift in the following manner
self.wamp?.config.deferredWampCRASigningBlock?(str : String , { (str2 : String) -> Void in
})
but I get this error
Cannot convert value of type 'String.Type' to expected argument type 'String!'
Any suggestions would be appreciated.
It means you're passing the data type. Please pass the value.
Lets walk through what deferredWampCRASigningBlock
is:
((String!, ((String!) -> Void)!) -> Void)!
This is a void function that takes two things:
So when you call it, you must pass it those things. A string and a function.
let challenge = "challenge"
let finishBLock: String! -> Void = { signature in }
self.wamp?.config.deferredWampCRASigningBlock?(challenge, finishBlock)
From some of your comments, you seem to not know what challenge
should be at this point. That suggests you should not be calling this function. This function is intended to be called by the part of the program that does know challenge
is.
The confusion may be related to "when I try to instantiate it." The code you've given doesn't instantiate anything. It is trying to call the function. Perhaps what you really meant was to create the function and assign it:
self.wamp?.config.deferredWampCRASigningBlock =
{ (challenge: String!, finishBlock: ((String!) -> Void)!) -> Void in
// ...
}
Try this
self.wamp?.config.deferredWampCRASigningBlock = {( challenge: String!, finishBlock) -> Void in
//calculate signature using any algorithm and return in finishBlock see below example
let sign = challenge.hmacSHA256DataWithKey(“secretKey”)
finishBlock(sign)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With