I am writing a general method that takes a dictionary and a given type in the parameters for assembling an object.
For example, if you make a SOAP request to receive a movie and postpone the answer in the dictionary, you can do:
var movie : Movie = myGenericMethod(dic : Dictionary, objectToIntrospect : Movie()) as Movie
Works with:
- Simple object
- Complex object
But I have a problem if you have an array of objects. So, imagine that your movie object contains an array of actors ...
With reflection, I get all types of class attributes. In doing so, I create an array of any object that contains my types. For example, an object contained in another object (Actor in Movie):
var anyType : Any = typesOfProperties[i]
var objectType : NSObject = anyType as NSObject
var otherDico : NSDictionary = ConverterUtilities.extractDictionaryFromOtherDictionary(dict, dicoName: property, soapAction: soapAction) as NSDictionary
var propertyObject: NSObject = self.buildAnyObjectWithDictionary(otherDico, soapAction: "", objectToIntrospect:objectType.self) as NSObject
ConverterUtilities.setPropertyValue(property, value: propertyObject, objectToReturn : myObjectToReturn, isObject : true)
It works fine ... If I have only one actor in my movie object, "propertyObject" will be of type Actor, and this will call objectType - an Actor object.
, , Array, objectType "Swift._NSSwiftArrayImpl" anyType return "([myproject.Actor])".
, , . , Actor!
, :
var objToAdd: NSObject = self.buildAnyObjectWithDictionary(newDic, soapAction: "", objectToIntrospect: Actor()) as NSObject
arraySpecific.append(objToAdd)
, , . , ! :
var objToAdd: NSObject = self.buildAnyObjectWithDictionary(newDic, soapAction: "", objectToIntrospect: anObjectWithActorType) as NSObject
arraySpecific.append(objToAdd)
( - objectToIntrospect)
, Any (: ([myproject.Actor]) ?
! !
PS: , , :)