0

I am using parse to verify whether a user exists (for example: an other user searches for "userX" and if "userX" exists he will send him a message).

On Parse website they recommend the following code:

var query = PFUser.query()
query.whereKey("gender", equalTo:"female")
var girls = query.findObjects()

Referred to : https://www.parse.com/docs/ios_guide#users-querying/iOS

I am using that code transformed it to:

 var query = PFUser.query()
 query.whereKey("username", equalTo:typeName.text)
 var usernameP = query.findObjects()

But then when i look at println(usernameP) I get an array.
But i want to transform the username ("treert" in this case) into a String that I can put in a label.

Does anybody know how to do that.

Thanks a lot!

rickerbh
  • 9,731
  • 1
  • 31
  • 35

1 Answers1

0

As you've discovered, usernameP contains an array. The clue is in the function you've called findObjects (plural). Your query will return all objects where username = typeName.text.

If you only want the first object found, then you will need to call query.getFirstObject().

An alternative is to continue to call findObjects(), but then process the array of results, extracting the object you think is the correct one (assuming the array has more than 0 objects in it), and set the name based on that object.

rickerbh
  • 9,731
  • 1
  • 31
  • 35