Skip to content

Instantly share code, notes, and snippets.

@clarkeben
Last active September 7, 2023 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkeben/9db4ceb06e27cfffcdd9e642b9a0956e to your computer and use it in GitHub Desktop.
Save clarkeben/9db4ceb06e27cfffcdd9e642b9a0956e to your computer and use it in GitHub Desktop.
String-to-Int
func convertIntToString(_ string: String) -> Int {
guard let intValue = Int(string) else { return 0 }
return intValue
}
convertIntToString("123")
let myAge = "101"
if let age = Int(myAge) {
print(age)
} else {
print("Failed to convert")
}
let myAge = "101"
var intAge = Int(myAge) //Optional(101)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment