I'm attempting to make a GET request on a Parse database I created using the built-in REST API. The API call is to be made when a user enters text into a UISearchBar, with the ultimate goal being to display the returned data in a UITableView. The code below only captures my attempt to make a valid HTTP request, where I am trying to see if "Query1" matches the search string ("Query1" is a parameter in my Parse database that essentially serves as an associated search term).
//Mark - UISearchBarDelegate
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
makeRequest(searchBar.text)
}
func makeRequest (searchString : String) {
//REST API call to the sampleObjectData class
var request = NSMutableURLRequest(URL: NSURL(string: "https://api.parse.com/1/classes/sampleObjectData")!)
let session = NSURLSession.sharedSession()
request.HTTPMethod = "GET"
//THIS IS MY TROUBLE AREA
var params = urllib.urlencode({"where";:json.dumps({
"Query1": "\(searchString)"
})})
var error: NSError?
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &error)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
//The kAppId & kRestAPIKey calls are referencing contstants at the top of the file
request.addValue("X-Parse-Application-Id", forHTTPHeaderField: kAppId)
request.addValue("X-Parse-REST-API-Key", forHTTPHeaderField: kRestAPIKey)
var task = session.dataTaskWithRequest(request, completionHandler: { (data, response, err) -> Void in
var stringData = NSString(data: data, encoding: NSUTF8StringEncoding)
println(stringData)
})
task.resume()
}
The result is code that will not build, as I cannot figure out how to apply parameters to the Parse REST API using Swift. Any help would be appreciated.