Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert value of type 'String.Type' to expected argument type 'String!'

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.

like image 240
Vijay Sanghavi Avatar asked Nov 23 '15 11:11

Vijay Sanghavi


3 Answers

It means you're passing the data type. Please pass the value.

like image 162
Sanjith Bravo Dastan Avatar answered Nov 18 '22 10:11

Sanjith Bravo Dastan


Lets walk through what deferredWampCRASigningBlock is:

((String!, ((String!) -> Void)!) -> Void)!

This is a void function that takes two things:

  • a String!
  • a void function that takes a String!

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
    // ...
}
like image 36
Rob Napier Avatar answered Nov 18 '22 10:11

Rob Napier


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)
    }
like image 1
Dhaval Gulhane Avatar answered Nov 18 '22 12:11

Dhaval Gulhane