I have an array ["abc", "94761178","790"]
["abc", "94761178","790"]
I want to iterate each and check is a String or an Integer?
How to check it ?
How to convert "123" to integer 123
Here is a small Swift version using String extension :
Swift 3/Swift 4 :
extension String { var isNumber: Bool { return !isEmpty && rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) == nil } }
Swift 2 :
extension String { var isNumber : Bool { get{ return !self.isEmpty && self.rangeOfCharacterFromSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet) == nil } } }
2.1m questions
2.1m answers
60 comments
57.0k users