Convert String to Int Swift
In this article, we will discuss how we can convert String to its equivalent integer value in swift. However, we can convert a string that contains integers only. The Integer's initializer can be used to convert a string that includes integers, as shown below.
It returns an optional value which means that it may or may not return a value. We need to use this int value very safely in our code because converting a string that doesn't contain an integer will result in nil. However, we can safely unwrap this, as shown below.
We can convert a string into an integer by converting it first into NSString and use the integerValue property of it as shown below.
Next TopicHigher-Order Functions