Vijay Sanghavi
Vijay Sanghavi

Reputation: 340

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.

Upvotes: 6

Views: 28733

Answers (5)

Rahul Fate
Rahul Fate

Reputation: 1

cell.lblname?.text = String(describing: tasks[indexPath.row])
cell.lbladdress?.text = String(describing: tasks[indexPath.row])
cell.lblphone?.text = String(describing: tasks[indexPath.row])

Upvotes: -2

Sanjith Bravo Dastan
Sanjith Bravo Dastan

Reputation: 449

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

Upvotes: 21

Dhaval Gulhane
Dhaval Gulhane

Reputation: 157

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)
    }

Upvotes: 1

Rob Napier
Rob Napier

Reputation: 299275

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
    // ...
}

Upvotes: 2

Kele
Kele

Reputation: 11

You'r passing String.Type not string value.

Instead of:

self.wamp?.config.deferredWampCRASigningBlock?(str : String , { (str2 : String) -> Void in

    })

It should be:

self.wamp?.config.deferredWampCRASigningBlock?(str : "some string" , { (str2 : String) -> Void in

        })

Upvotes: 0

Related Questions