So, full disclosure: I'm a newbie to Swift.
I'm working on an app, trying to get a label in a custom cell to display a DOUBLE value. I've tried to do an if let conditional binding to cast it from a string to a double, but my source isn't an optional type, and I can't make it optional. So I'm not sure how to do this.
Here are the specific errors:
initializer for conditional binding must have Optional type, not 'Double'
Cannot assign value of type 'Double?' to type 'String?'
No exact matches in call to initializer
and here's the code:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DemoTableViewCell", for: indexPath) as! DemoTableViewCell
cell.partNameLabel.text = parts[indexPath.row].partName
// Convert string value to double
if let value = parts[indexPath.row].partCost {
cell.partCostLabel.text = Double(value)
} else {
cell.partCostLabel.text = 0.00
}
cell.purchaseDateLabel.text = parts[indexPath.row].purchaseDate
return cell
}
Thanks in advance!