Convert string to nsnumber,integer and trim the whitespaces in the string swift
Solution:
extension String {
var trimStr:String? {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
}
func nsNumber() -> NSNumber {
return NSNumber(value: Int64(self)!)
}
func toInt() -> Int {
return Int(self) ?? 0
}
}
Comments
Post a Comment