How to convert a String to an Int in Swift?
Hello everyone! I just started learning Swift and encountered a problem when working with numbers and strings.\n\nI have an app that receives data from a text field. The user enters a number there, for example, "123". I need to use this number for mathematical operations. I'm trying to do this:\n\n```swift\nlet userInput = "123"\nlet result = userInput + 10 // Error!\n```\n\nBut the compiler gives an error: "Binary operator '+' cannot be applied to operands of type 'String' and 'Int'". I understand that `userInput` is a string, and 10 is an integer. How do I convert the string to Int?\n\nI tried using `Int(userInput)`, but I get a strange type "Int?" with a question mark. And if the user enters something non-numeric, like "abc", the app crashes with an error. How to do it correctly?