swift - Add array object not init -


i have method init class object json. method this:

func getlist (dic : array<[string:anyobject]>)  -> array<dog> {     let dogs : nsmutablearray = nsmutablearray()     mydic in dic {         let dog = dog.init(dog: mydic)         dogs.addobject(dog)     }     return nsarray(dogs) as! array<dog> } 

and can present on tableview without issue. right want make pagination list. if run method getlist again init new object , replacing old one. how can add new object exisiting. don't want create separate object same property.

you need add member variable append to. so:

var dogs: [dog] = [] 

and call getlist this:

dogs += getlist(dic: mydic) 

by way, can make getlist method simpler, this:

func getlist(dic: [[string: anyobject]]) -> [dog] {   return dic.map(dog.init) } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -