I am using the Eureka form library found here . I am trying to iterate over the dictionary values of the form and only print the values that are true; not nil or not false. So far I have
let valuesDictionary = form.values()
for (_, version) in valuesDictionary
{
if version != nil || version as! Bool != false // error here
{
print (version!)
}
}
I am getting the following error on the if statement:
fatal error: unexpectedly found nil while unwrapping an Optional value
Do it like this:
for (_, version) in valuesDictionary
{
if let version = version, version as? Bool != false {
print(version)
}
}
This will translated as:
if let version = version
: if there is a value ( version is not nil
) After checking if it's not null ( optional binding ), as a where condition:
version as? Bool != false
version as? Bool != false
: checks tow points: 1- is version
could be cast to Bool
.
2- If the first point is true, check if version is not false
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.