Wednesday, 15 August 2012

ios - Query users by name or email address using Firebase (Swift) -


Firebase and Swift and I 'd come to inquire if there is some problem. So basically there are two things I want to do:

  1. Ask questions from my users and search only for a certain string in their name (or email address) And add them to an array.
  2. Find all your users and add them to an array.

The relevant portion of my data for this query looks like this: here image details enter

as you can see, I am using Saidlagin of Fayrbej (Later I also want to add Facebook) and I can store its users by UID I am here.

One part of my rule file looks like this:

  "registered_users": {".read": True, ".write": True, " .indexOn ": [" name "]}  

So everyone should read and write access to this should have been part of my data.

I've read part of "recovery data" Fayrbej iOS guide on its website and in accordance with the Guide, the user name and must work my address to receive e-mail address at least I think so but it is not here is my code:

  getUsersFromFirebase function () {go registeredUserRef = firebaseRef.childByAppendingPath ( "registered_users") registeredUserRef.queryOrderedByChild ( "name") observeSingleEventOfType (.Value, withBlock : {Snapshot in? If known as email = snapshot.value ["email"] String {println ( "\ (snapshot.key) Email: \ (email)")} If the name = snapshot.value [ "name"] as string? {Println ( "\ (snapshot.key) name : \ (name) ")}})}  

I saw that firebase guides, they always utilize ChildAdded and value, but value for me makes more sense is. Output is nothing but the output and the child's output is only one user, i.e. which is currently logged.

So my questions are:

  1. Do I do it with my existing data structure or do I have to get rid of the story by the UID users?
  2. If yes, how do I have to change my code to do this work?
  3. If not, what would be the best way to store your users and possibly name inquiries?
  4. How can I query for example "hardworking" and only user get simple login: 1 (Max Masterman)?

I hope my description is detailed enough to help you thx in advance.

Supplement :

The weird thing is, that says "Guide to recover" data, it is possible that data from the query and sorting height.

Data:

Enter image details here

Inquiry code: Enter image details here

And do not do that at all What i want to do

I have participated in situations where I wanted to draw data from child nodes.

They are like a light duty query.

Secondly, if you want to query, you have to adjust your data, because one query is only one level depth (can not actually query data in child notes) < / P>

Lastly - if you do not want to scale your data, a conceptual choice to answer your question;

  1. If possible, ObserveSingleEventOfType: FEventTypeValue on registered user node. All of the users registered as this snapshot will be read.
  2. Repeat the snapshot and read each user (as dictionary objects) in an array
  3. Then use NSPredicate to remove an array of users that you want.

I have run according to many tests and demonstrations, unless you have thousands of users.

Hope that helps!


No comments:

Post a Comment