Swift Prog. Language: In an if statement, the conditional must be a Boolean expression is incorrect
| Originator: | mc | ||
| Number: | rdar://17358576 | Date Originated: | 2014-06-18 |
| Status: | Closed | Resolved: | |
| Product: | Documentation | Product Version: | |
| Classification: | Other Bug | Reproducible: | Always |
var optionalString: String? = nil
if optionalString {
"non nil"
} else {
"nil"
} Will output "nil".
if optionalString isn't a Boolean expression. One could argue about that, but I think of a Boolean expression more as == true or == false,
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Apple Developer Relations
Engineering has determined that this issue behaves as intended based on the following:
The full answer is that it can be any data type that conforms to the LogicValue protocol, as discussed in the Reference (link below). That's too much detail for the guided tour though.
https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-XID_915
We are now closing this bug report.
If you have questions regarding the resolution of this issue, please update your bug report with that information.
Please be sure to regularly check new Apple releases for any updates that might affect this issue.