I am converting Java code to Swift. This is the Java code
try {
if (filter == null || Float.parseFloat(ew.getMagnitude()) >= Float.parseFloat(filter))
liist.add(ew);
} catch (NumberFormatException e) {
}
In Swift, currently this is what I have
do {
if let toFilter = filter, Float(ew.magnitude ?? "0") >= Float(toFilter ?? "0") {
list.append(ew)
}
}
else {
list.append(ew)
}
} catch {
}
Currently
- it even gives out an error that I have to add a ! after the Float() because "Force-unwrap using '!' to abort execution if the optional value contains 'nil'"
- But i do not want that, that is why I placed th do/catch there
Please enlighten. Thank you