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

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift