Swift JSON parsing with Dictionary with Array of Dictionaries
<p>I am a beginner in iOS development with Swift language. I have a JSON file contains the data as below.</p>

<pre><code>{
    "success": true,
    "data": [
             {
                 "type": 0,
                 "name": "Money Extension",
                 "bal": "72 $",
                 "Name": "LK_Mor",
                 "code": "LK_Mor",
                 "class": "0",
                 "withdraw": "300 $",
                 "initval": "1000 $"
             },
             {

             },
             {

             },
             ]
}   
</code></pre>

<p>I want to parse this file and have to return the dictionary which contain the data in the JSON file. This is the method I wrote. </p>

<pre><code>enum JSONError: String, ErrorType {
    case NoData = "ERROR: no data"
    case ConversionFailed = "ERROR: conversion from JSON failed"
}

func jsonParserForDataUsage(urlForData:String)-&gt;NSDictionary{
    var dicOfParsedData :NSDictionary!
    print("json parser activated")
    let urlPath = urlForData
    let endpoint = NSURL(string: urlPath)
    let request = NSMutableURLRequest(URL:endpoint!)
            NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) -&gt; Void in
                do {

                    guard let dat = data else {
                        throw JSONError.NoData
                    }
                    guard let dictionary: NSDictionary = try NSJSONSerialization.JSONObjectWithData(dat, options:.AllowFragments) as? NSDictionary else {
                        throw JSONError.ConversionFailed
                    }

                    print(dictionary)
                    dicOfParsedData = dictionary

                } catch let error as JSONError {
                    print(error.rawValue)
                } catch {
                    print(error)
                }
                }.resume()

          return dicOfParsedData

}
</code></pre>

<p>When I modify this method to return a dictionary, it always return nil. How can I modify this method.</p>