Fetching the definition of a word using a REST API This is the code I'm using to GET the definition of a word from Wordnik's REST API. I don't want to ignore any error but this is causing the code to be ridiculously long. I'm new to Swift so I'd appreciate it if someone could explain how best to trim it down.

class func define(params: DefinitionParameters!, delegate: WordnikDictionaryDelegate!){

        if let url = url(definitionParams: params){

            NSLog("URL: \(url)")

            let session = NSURLSession.sharedSession()
            let task = session.dataTaskWithURL(url, completionHandler: { (data, response, error) -&gt; Void in

                var error : NSError?
                if let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &amp;error) as? NSMutableArray{

                    NSLog("Response: \(json)")

                    if json.count == 0 {

                        delegate.dictionaryDidLoad(
                            nil,
                            forWord: params.word,
                            error: self.buildError(404, message: "No definitions found")
                        )

                    }else if let definitionJSON = json[0] as? NSMutableDictionary{

                        delegate.dictionaryDidLoad(
                            definitionJSON.valueForKeyPath("text") as? String,
                            forWord: params.word,
                            error: nil
                        )

                    }else{

                        delegate.dictionaryDidLoad(
                            nil,
                            forWord: params.word,
                            error: self.buildError(401, message: "Unexpected Result Format")
                        )

                    }

                }else{

                    delegate.dictionaryDidLoad(
                        nil,
                        forWord: params.word,
                        error: self.buildError(401, message: "Unexpected results format")
                    )

                }

            })

            task.resume()

        }else{

            delegate.dictionaryDidLoad(
                nil,
                forWord: params.word,
                error: self.buildError(400, message: "Invalid URL")
            )

        }

    }
Inside the if let json = ... { ... }, all the execution branches will call delegate.dictionaryDidLoad,
and the value of forWord is always params.word.
Instead, you could initialize value and error to nil,
set them in the appropriate conditional branches,
and finally call the delegate.
Something like this:

if let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &amp;error) as? NSMutableArray{

    NSLog("Response: \(json)")

    if json.count == 0 {
        error = self.buildError(404, message: "No definitions found")
    } else if let definitionJSON = json[0] as? NSMutableDictionary{
        value = definitionJSON.valueForKeyPath("text") as? String,
    } else {
        error = self.buildError(401, message: "Unexpected Result Format")
    }
} else {
    error = self.buildError(401, message: "Unexpected Result Format")
}

delegate.dictionaryDidLoad(
    value,
    forWord: params.word,
    error: error
)