last day (14 days later) » 

9:41 AM
1
A: UITableView with MVVM using Swift

Jaydeep VyasYou are doing good job, but you can even improve you product model with adding following function to get array of direct models. It is very useful when you have create array from web Api response. class Product : NSObject { var imgUrl : String! var name : String! var...

 
Thanks alot. Little bit of confusion in modelsFromArray method.
 
okey what is confusion
 
You are using two arrays. one is while using and other is Product model class.
 
first array is use to demostrate you, it may be server response than you can directly pass the response to generate array of models. also note i have updated code for your cell class also
 
Thanks alot Jaydeep. Its really helpful. I will update my code.
One more doubt. YOu have used implicit uwrapped variable. For example var quantity : Int!. If I want to access it from ViewController class, the value is Options(1). AS per my knowledge Implicit Unwrapped` object cant be force unwrap. Can you tell me why?
 
9:41 AM
@Dhanunjaya you can replace the init method by name = (dictionary["name"] as? String ) ?? ""
 
Actually issue is not with type String. Issue is with Int type.
 
9:55 AM
Whats issue you found
quantity = (dictionary["quantity"] as? Int ) ?? 0
 
If I want to access the same in ViewController like this
cell.productQuantity.text = "(product.quantity!)"
Observer that quantity is having exclamation mark. If i will use like this then only I will get the value otherwise I will get Optional(1)
 
Oh it just because of " " double quotation
simple cast to string
String(product.quantity!)
 
10:11 AM
String(product.quantity)...! is not required here. Thanks alot for your time...It works fine
 

last day (14 days later) »