#  I am hosting the DreamFactory API web server on my localhost and I am accessing it through my iOS app.

**URL:** <https://community.dreamfactory.com/t/i-am-hosting-the-dreamfactory-api-web-server-on-my-localhost-and-i-am-accessing-it-through-my-ios-app/4738>\
**Category:** Connecting to SQL\
**Tags:** community\
**Created:** [December 11, 2018, 9:49pm UTC](https://community.dreamfactory.com/t/i-am-hosting-the-dreamfactory-api-web-server-on-my-localhost-and-i-am-accessing-it-through-my-ios-app/4738 "2018-12-11T21:49:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarikaA](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/sarikaa/32/1189_2.png) [@SarikaA](https://community.dreamfactory.com/u/SarikaA)\
**Post date:** [December 11, 2018, 9:49pm UTC](https://community.dreamfactory.com/t/i-am-hosting-the-dreamfactory-api-web-server-on-my-localhost-and-i-am-accessing-it-through-my-ios-app/4738/1 "2018-12-11T21:49:16Z")

</div>

I’m new to swift and iOS development in general, However I can’t motivate my capacity to restore the outcome from an API GET ask. I am running a [Microsoft SQL server](https://mindmajix.com/msbi-training) on my companion’s PC and I am remotely getting to it with DreamFactory. DreamFactory is making and dealing with the API for the SQL queries. I am hosting the DreamFactory API web server on my localhost and I am accessing it through my iOS app.

This is what I have so far.

```auto
func validId() -> Bool {
    var queryId: Int = 0 // just for testing

    let table = "SM.Customers"
    // this url looks like ( http://localhost:8080/api/v2/db/_table/SM.Customers/1989/?api_key=065dce537)
    let url = URL(string: "\(urlString)\(table)/\(self.id)?api_key=\(self.api_key)")!

    URLSession.shared.dataTask(with: url, completionHandler: {
        (data, response, error) in
        if(error != nil){
            print(error.debugDescription)
        }else{
            do{
                self.userData = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String: AnyObject]
                OperationQueue.main.addOperation {
                    queryId = self.userData["CustId"] as! Int
                    print(queryId)
                }

            }catch let error as NSError{
                print(error)
            }
        }

    }).resume()

    return (String(queryId) == self.id)

}

```

I can do things under `OperationQueue.main.addOperation {...}` with the data that I pull from the `db` , but I can’t really return a value or assign the value to a variable outside of the `task` code block. This function will `print(queryId)` as `1989` but it will return `false` because it’s reading `(String(queryId) == self.id)` as `(0 == 1989)` .

Any advices how I can resolve this?
