String Extension & Computed Property
You can also add to String
a computed property.
The logic inside the computed property is the same described by OOPer
extension String {
var isInt: Bool {
return Int(self) != nil
}
}
Now you can
"1".isInt // true
"Hello world".isInt // false
"".isInt // false