How can check If result is __NSCFNumber?

237 Views Asked by At

I'm running evaluate function to run javascript. However, It runs another javascript code inside it so that I need to wait sometime to get the original result. Till the original result, It returns a number. I can wait for the result but I need to check If the return result is an integer or a string. How can I do that? If I don't do that check because first results are int, I'm getting this error when try to equal result to a string variable.

Could not cast value of type '__NSCFNumber' (0x10f703540) to 'NSString' (0x10e130c40).

My code is; (writeMSG function returns number If I don't wait too much but If I wait It will return a string)

func getLink(){
    while(a != nil)
    {
        evaluate(script: "writeMSG()") {(result,error) in
         print(result!)
                self.a = result as! String
            }
        }
    }
    flag = 1
}
1

There are 1 best solutions below

0
On

I check it with if(result is NSString) code

 func getLink(){
        while(a != nil)
        {
            evaluate(script: "writeMSG()") {(result,error) in
             print(result!)
               if(result is NSString){
                    self.a = result as! String
                 }
                }
            }
        }
        flag = 1
    }