Last active
September 7, 2023 10:27
-
-
Save clarkeben/9db4ceb06e27cfffcdd9e642b9a0956e to your computer and use it in GitHub Desktop.
String-to-Int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func convertIntToString(_ string: String) -> Int { | |
guard let intValue = Int(string) else { return 0 } | |
return intValue | |
} | |
convertIntToString("123") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myAge = "101" | |
if let age = Int(myAge) { | |
print(age) | |
} else { | |
print("Failed to convert") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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