1

This is my code:

if let img = UIImage(named: imageName)
{image = img}
else{image = UIImage(named: "default")!

However, it still comes up with the error: fatal error: unexpectedly found nil while unwrapping an Optional value. Need help, thanks!

Yp Ng
  • 5
  • 3
  • Do you have `"default"` as an image in your bundle? – ABakerSmith Sep 08 '15 at 09:01
  • yes, i have it (default.jpg) – Yp Ng Sep 08 '15 at 09:03
  • 1
    Try `image = UIImage(named: "default.jpg")!`; leaving the extension off will cause a png to be looked for. – ABakerSmith Sep 08 '15 at 09:05
  • I try it with UIImage(named: "default.jpg")! It comes out with another errors Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3347.44/UITableView.m:6245 erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier rProduct Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' – Yp Ng Sep 08 '15 at 09:09
  • 3
    @YpNg: ... which is a completely different and unrelated problem (and if you search for that error messages you should find lots of answers to that one). – Martin R Sep 08 '15 at 09:14
  • @YpNg as @ABakerSmith said you must use default.jpg. For `dequeueReusableCellWithIdentifier` make sure you added delegate for tableview and custom cell is called. – AAA Sep 08 '15 at 09:38
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](https://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Cristik Mar 19 '18 at 06:02

0 Answers0