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

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift