Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

sending information

Hi,

I'm trying to create an application where there's a "leader" of the app and the "leader" will write something and it'll be sent out to all the users that are on the app. So for example, people sign up and the users that signed up can receive information that the leader has sent.

I was wondering where to begin with that. I already have the sign up part created - all I was wondering was how to have a leader & that leader send information to all users. :) Any help is appreciated. Thank you :)

4 Answers

Off the top of my head, I'd probably approach it like this.

If you have a sign-up process, it means you probably have some way in your database to distinguish between people, say a unique UID. The followers could "sign up" to that leader by you appending their follower UID to a part of the leader's "follower" array within their specific section of the database. I would probably also track who the follower is "following" as well and write the leader's UID to their specific section. If you want to send push notifications, you'll also have to track their unique device ID which you can write when the follower logs in.

Then when a leader sends a message, you can iterate through the "follower" array and notify each of the followers. Does that make sense?

Ian Han , thanks for your reply.

Okay. So, I would create a unique UID, and that would be my 'leader'. Then users could sign up and my UID would have to accept them?

Thanks! :)

Each leader and user should have their own unique UID. The user would "follow" that leader's UID and in the leader's database section, the user's UID (and device ID depending on what you want to do) would be written in to connect them together, basically.

If you want to add a friend request type feature, just write it to a "pending" section instead of immediately to "followers", populate a table view with the pending and have in didSelect, an alert controller (or whatever UI device you want) to accept or reject.

Ian Han Could you break that down into beginner knowledge?
I'm using the Ribbit tutorial on this site and I am trying to learn how to do this. Could you give example code? I'm not trying to have you do everything, and the information you gave is a good kick in the right direction, but I'm just trying to learn how that would look like.

Thanks again

There's a lot of factors that go into this that prevent me from writing the code since it's pretty specific to your situation (and I don't know what Ribbit is? - I think its a twitter clone from a quick google search?). What are you using as your backend? Databasing is, at times, a conceptual exercise than it is strictly a code one. You need to think of it like this:

  1. How do I identify each leader and follower? This could be through UID, whatever, doesn't matter. You just need to make sure that in some way you're tracking who is who and when a user follows a leader, you are making a connection in some way.

  2. When a user follows a leader, what happens? How do you track this? In the way I explained above, I'm literally writing their identification to a section within the leader's database section, allowing me persistence to read it later. This is the C in CRUD

  3. When a leader wants to send a message, how is it displayed to the user? Here's where that reading coming into play. Everything in development is data manipulation. Let's say we're using my example, you "created" the follower section. Now you read it to see who is "following" this leader. You then can use that identification information in whatever way you need, whether its pushing a message to them, or sending a push notification, whatever. This is the R in CRUD.

Ian Han , sorry for the late reply.

It's not Ribbit, sorry. It's the self-destructing messaging app Ben did. I'm using that as my foundation and the backend I'm using is Parse.

You've given me some good information. I'll take it and do some more research. Glad I have a better understanding! Thanks for your help!