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

Convert NsNumber, NSDate to String in iOS Swift

store cgpoint in userdefaults iOS swift