Convert boolean to string and Int extension function iOS swift

 Solution:

extension Bool {

    var toString:String! {

        String(describing: self)

    }

    var toInt:Int! {

        return self == true ? 1 : 0

    }

}


You can directly call as like below


let isDone:Bool = false


then call to string as


isDone.toString()


then call to Int as


isDone.toInt()


Comments

Popular posts from this blog

store cgpoint in userdefaults iOS swift

libc++abi: terminating due to uncaught exception of type NSException iOS swift