简体   繁体   中英

FB and Twitter feed in ios application

i want to create global feed for user from FB and Twitter, so i'm using FB-iOS-SDK and TwitterSdk for this. I'm getting both feeds as NSArrays (of dictionaries of course) and now i want to load the last 10 posts by user from both feeds (ordered by time). For example:

1)Post from twitter - 04.07.14 10:05 PM

2) Post from twitter - 04.07.14 09:12 PM

3) Post from facebook - 04.07.14 10:13 AM

4) Post from twitter - 03.07.14 11:15 AM

I have methods:

- (void)twitterTimeline:(NSString *)maxid :(NSString *)screename :(NSInteger *)count

-(void)fbWall: (NSString *)maxid :(NSString *)screenname :(NSInteger *)count

screenname-username maxid-number to skip from last post count-count of post

But i don't know what is the best way to organize this data? I just need a simple TableView with this data so when i'm scrolling down i can get more and more news (increase maxid parameter).

I do not ask you how to programmatically accomplish this, I just need some advice how to do it better (combine two arrays into one or something else)

Your question is not very specific so I'm going to assume you want a way to store both types of posts in one list. There are a few clean ways to do this.

  1. Have 2 separate class types that both conform to a protocol which contains the properties and methods they both need to have (id, screen name, timestamp, post, etc).

  2. If all the fields are going to be the same with no Facebook or Twitter specific fields, you can have a single Post class that you use for both, with perhaps a simple enum flag indicating the "type" to be Facebook or Twitter.

  3. Have a base class with all shared fields (like the ones you would have in the protocol from the first item), and a subclass for each type of post.

EDIT

Once you have all the posts in your array, just sort the array on the timestamp (see how to sort by NSDate here ). Then you can just grab the first 10 elements and put them in a new array or do whatever you want with them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM