Profstyle Profstyle - 7 months ago 47
Swift Question

Data parsing With Soap Engine in Swift

in swift 2.0 using SOAP Engine to parse data.

having a problem while taking data into an NSArray.

soap.requestURL("URL",
soapAction: "ActionURL",
completeWithDictionary: { (statusCode : Int, dict : [NSObject : AnyObject]!) -> Void in

var result:Dictionary = dict as Dictionary
NSLog("%@", result)


From NSLog the data which i receive is :

{
Results = {
Result = (
{
ILCE = "ALA";
KOD = 21894;
MAHALLE = "ATATURK";
MAHALLEKOD = 57;
YOL = "ATATURK";
},
{
ILCE = "DEN";
KOD = 21894;
MAHALLE = "KAZIM D\U0130R\U0130K";
MAHALLEKOD = 257;
YOL = "ATAT\U00dcRK";
},
{
ILCE = "AL\U0130A\U011eA";
KOD = 21894;
MAHALLE = "K\U00dcLT\U00dcR";
MAHALLEKOD = 517;
YOL = "ATAT\U00dcRK";
},


I only want to get the Result instead of Results into the NSArray. Here is what i do :

let sonuclar = result["Results"]

-> let aramalar: NSArray = sonuclar as! NSArray
print(aramalar)

self.aramalar = aramalar
self.table.reloadData()

}) { (error : NSError!) -> Void in

NSLog("%@", error)
}


But at this point on "aramalar" i m reciving an error such


Could not cast value of type '__NSDictionaryM' (0x1038ced38) to 'NSArray' (0x1038ce900).


Thanks in advance !

Answer

found the answer.

Here what have to do :

let sonuclar = dict["Results"]!["Result"]

"Results" is a dictionary with one key named "Result", this key named "Result" is a array of dictionary.