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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift