Firstly there is a base class be called BaseModel ,below is the code:
class BaseModel : NSObject
{
var code:Int?
var message:Any?
public func setDictionaryToAttributes(dictionary_is dictionary:Dictionary<String,Any>?)->Bool
{
guard let dic:Dictionary<String,Any> = dictionary else {return false}
for (key,value) in dic {
let someType = type(of: value)
debugPrint("\(String(describing: someType.self))")
debugPrint("\(String(describing: someType))")
if someType is Array<Any>.Type { //i can't get TestListItemModel string
debugPrint("\(String(describing: someType))")
}
}
self.setValuesForKeys(dic)
return true;
}
}//class BaseModel end
and there is another class inherited from BaseModel
class TestListModel: BaseModel {
var tatalink:Any?
var items:Array<TestListItemModel>?
func setValuesFrom(jsonData j:JSON) { //j is a swifyJson object
guard var dic = j.dictionaryObject else {return}
if self.setDictionaryToAttributes(dictionary_is: dic)==false {
return
}
}
}
there is a class TestListItemModel for submodel in TestListModel
class TestListItemModel:BaseModel {
var imgurl: Any?
var title: Any?
}
Question is: I want to automatically parse all attribute values in the BaseModel class from json data. in func analysetDictionaryToAttributes: I can find which one is Array, but I don't know how to get this type and Continue to call it's analysetDictionaryToAttributes func.