We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xcode 12.4 (12D4e)
md5: 5fac6185a515f864fb550d8e0fa22676
Issue Description:
https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html
You can rewrite the possibleNumber example from the Optionals section to use optional binding rather than forced unwrapping:
possibleNumber
if let actualNumber = Int(possibleNumber) {
print("The string "(possibleNumber)" has an integer value of (actualNumber)")
} else {
print("The string "(possibleNumber)" couldn't be converted to an integer")
}
This code can be read as:
"If the optional Int returned by Int(possibleNumber) contains a value, set a new constant called actualNumber to the value contained in the optional."
Int
Int(possibleNumber)
actualNumber
==============
Error:
The first line of code is wrong. The compiler will give this error message: "Value of optional type 'Int?' must be unwrapped to a value of type 'Int'"
Need to change the document or change the compiler. Not sure which one is correct.
The text was updated successfully, but these errors were encountered:
Could you clarify what part of the code results in that error? Looking at https://godbolt.org/z/qb4Gjz, the code compiles fine without any error.
Sorry, something went wrong.
No branches or pull requests
Environment
Xcode 12.4 (12D4e)
Additional Detail from JIRA
md5: 5fac6185a515f864fb550d8e0fa22676
Issue Description:
https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html
Optional Binding
You can rewrite the
possibleNumber
example from the Optionals section to use optional binding rather than forced unwrapping:if let actualNumber = Int(possibleNumber) {
print("The string "(possibleNumber)" has an integer value of (actualNumber)")
} else {
print("The string "(possibleNumber)" couldn't be converted to an integer")
}
This code can be read as:
"If the optional
Int
returned byInt(possibleNumber)
contains a value, set a new constant calledactualNumber
to the value contained in the optional."==============
Error:
The first line of code is wrong. The compiler will give this error message:
"Value of optional type 'Int?' must be unwrapped to a value of type 'Int'"
Need to change the document or change the compiler. Not sure which one is correct.
The text was updated successfully, but these errors were encountered: