Create Instance of class

When instanciating an array of ProductModel, I do this way and everything works fine:

@Published var products = [ProductModel]()

However If I just want one instance, I have an error:

@Published var product = ProductModel()

Missing argument for parameter 'from' in call

Why is this problem happening ? Thx

Answered by ForumsContributor in

Can you show enough code to reproduce the issue?

Accepted Answer

products is created as an empty array of type ProductModel, I.e. no product (ProductModel) has yet been instantiated. You will need to look at the definition of ProductModel to see what is required for initiation. You can do this in Xcode (jump to Definition), or autocomplete will probably prompt for the required/available parameters.

Create Instance of class
 
 
Q