I am currently creating an ios app using swift with parse/back4app as my back end. I am trying to return a query result from my server to my application. However, I am having trouble figuring out how to access the returned data. Attach is the console output of the returned data, my cloud function, and the application function catching the returned query. Thank you in advance
CONSOLE OUTPUT:
<UserLocation: 0x6000009c49c0, objectId: 4491TlDn5z, localId: (null)> {
latitude = "-26.2041028";
longitude = "28.0473051";
username = test0;
}
APPLICATION FUNCTION:
PFCloud.callFunction(inBackground: "UserLocationRecord",
withParameters: ["username": self.userName,
"longitude": locationInfo.coordinate.longitude,
"latitude": locationInfo.coordinate.latitude,
])
{ result, error in
let stat = result as! NSArray
print(stat[0])
print(error)
}
JAVASCRIPT CLOUD/SERVER FUNCTION:
Parse.Cloud.define("UserLocationRecord", (request) => {
const UserLocation = Parse.Object.extend("UserLocation");
const userLocation = new Parse.Query(UserLocation);
let query = new Parse.Query("UserLocation");
query.equalTo("username", request.params.username);
let results = query.find()
return results;
});
LOGS FROM CONSOLE OF SERVER:
2022-02-14T20:48:07.636Z - Ran cloud function UserLocationRecord for user BlSOr7wulW with:
Input: {"latitude":-33.8634,"longitude":151.211,"username":"test0"}
Result: [{"longitude":28.0473051,"username":"test0","latitude":-26.2041028,"createdAt":"2022-02-13T03:37:49.526Z","updatedAt":"2022-02-13T03:40:24.450Z","objectId":"4491TlDn5z","__type":"Object","className":"UserLocation"}]
Already investigated: It is not an Array, or Dictionary despite its look. i tried to index, it both with bracket and dot notation and nothing happens. In addition I tried using a for each loop and got an error back saying results in not iterable. Please help.