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
Post a Comment