Structs or Classes as Models in Swift
-
I want to implement IgListKit for my UICollectionView
This Library requires me to use “Class Model : ListDiffable”
Accoding to my current architecture I have “Struct Model : Decodable” As I use JSON Decoder in my NetworkService to retrieve Data
I have 2 struct, 1 for the Root and the 2 for my Array.struct Talents : Decodable { let status : String? let error : String? let response : String? } struct Talent: Decodable { let id: String let name : String let smallDesc: String let largeDesc : String }
\ I also have enum CodingKeys to match the keys for both structs
Following is the output I get Works well to be used in my UICollectionView
when I change these structs to class
class Talents : Decodable { var status : String? var error : String? var response : String? init( status : String,error : String, response : String){ status = self.status error = self.error response = self.response } }
This is the output I get, Which I am not sure how to make use of
-What are the changes I should make in order to resolve this, and apply : ListDiffable Protocol stubs to my Model class?
Service File with the instance of which in viewDidLoad of my CollectionVC I take the Data in an array.Find My Service Code on stackoverflow