How to change a variable within a request : I have a problem with coding in Swift. I'm using Xcode 9.1 and
I want to check if file exist and then change the context of a variable.
if I working with playgrounds, it wil work but coding in a viewport, nothing happens.
I check if the file named "nameoffile.xml" exist, using the statuscode, and then the var color need to change into "blue".
Below you will find my (not working) code.

Many thanks in advance!!!



    let url = URL(string: "http://myurl/nameoffile.xml")!
    var color = ""
    
    func checkFile()
    {
        let req = NSMutableURLRequest(url: url)
        req.httpMethod = "HEAD"
        req.timeoutInterval = 1.0
        var response: URLResponse?
        var task = URLSession.shared.dataTask(with: url) {(data, response, error) in
            if let httpStatus = response as? HTTPURLResponse
            { if httpStatus.statusCode == 200 {
                self.kleur = "blue"
                }
            }
        }

