0
class func getAllProjects(DOMAIN: String) -> JSON{
        var hovno: JSON?
        Alamofire.request(.GET, "https://\(DOMAIN).projektove.cz/projects.json")
            .responseJSON { (request, response, JSONresponse, error) in

                if( error == nil){
                    var responseJSON = JSONresponse as NSMutableDictionary
                    let json = JSON(responseJSON)

                    var projects = json["projects"] //Pole projektů

                    for (index: String, subJson: JSON) in projects {
                        println(subJson)
                        hovno = subJson
                        //mam cisty format JSONu, kazdy projekt zvlast v zavorkach
                    }


//                    var data = Projects(json: json).toDictionary()


                }else{
                    println(error)
                }
        }
        return hovno!
    }

Why is variable hovno still nil? his would work in every normal language. I declar variable in the beginning and then overwriting it with value subJson. In the end, I just return it. Why is this so hard in Swift and why is this happening? How can I return value?

Kotora
  • 135
  • 1
  • 8
  • 1
    You'll have to understand what an "asynchronous request" with a "completion handler" is. It is explicitly mentioned in the "Response Handling" section of https://github.com/Alamofire/Alamofire. – Martin R Dec 30 '14 at 10:17
  • Thank you! But still don't get how to work with that data. – Kotora Dec 31 '14 at 00:05

0 Answers0