Nil

I have a view which goes to my Store, gets data from an API and bringing back to the view.

var productId = 123
@ObservedObject var productStore = ProductStore()
   
  init() {
    productStore.getById(productId: self.productid)
  }

The object from ProductStore is coming back but when I try to use it:

Text(self.productStore.product!.title)

I get: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Why this is happening if the object doesnt have nil values ?

Answered by ForumsContributor in

I guess, you are using asynchronous methods incorrectly. Anyway, avoid using forced unwrapping. By the way, don't you think you should respond when you get comments and answers?

Accepted Answer

Nice thx

Nice thx

Nil
 
 
Q