ios - Swift Cast AnyObject to Block -
So I am using Salesforce SDK for the entire SDK and created bridging headers.
func sendRESTRequest (Request: SFRestRequest!, Failed Block: SFRestFailBlock!, Full Block: AnyObject!); Block Syntax, which is not translated into the most useful code. )
The complete block is AnyObject! I was able to get around this with
Var block: @objc_block (DataRPS: AnyObject!) - & gt; Zero = {I handle the response in the data response} restService.sendRESTRequest (request, unsuccessful block: {(error: NSError!) - & gt; absolute in} block: unsafe bit cast (block, AnyObject.self ))
So far it works fine, however, now I am trying to build unit tests for this code. I have created a mock class for SFRestAPI, which is the square where the function "sendRESTRequest" remains for testing purposes, I am passing the "document" and trying to fool the full divider: parameter which is from the REST service Will be back.
The issue is, I can not cast any object! For block like I was able to block any object from above.
Some of my efforts have been made:
var block = fullBlock as block @objc_block (AnyObject! -> Zero) var block 2: (AnyObject! - & Gt; zero) = unsafe bit cast (full block, (@Object_blok (AnyObject! -> Zero)))
Attempt, but these are only two that are relatively intelligent. So, is this possible in Swift? The problem is that I can not provide the "type" off the second parameter of the unsecured bit cast method. I want to close it so that I can call it in my fake method and pass it in some fake data.
The best way to handle this situation is to create your own typewase for your blocks:
typis MyFunBlock = @objc_block (DataRestation: Oibbase!) - & gt; Zero;
Then you can use it unsafecast:
var block: MyFunBlock = unsaffectBitCast (full block, MyFunBlock.self) as MyFunBlock;
Comments
Post a Comment