
I just started playing with Twitter API and was interested to see some good API’s in objective-c. The one i started to look at is created by Matt Legend
You can see his stuff here
Anyway after simply checking(svn co) out his repository, I was able to quickly build a simple client very quickly
Here is version 0.000001 alpha
Matt nicely uses the standard way of doing things in objetive c with async calls
- Delegate – call back mechanism
Your View Controller or what ever has to simply implement the protocol MGTwitterEngineDelegate and you are getting responses from Twitter
Here is my code
1 2 3 | twitterEngine=[[MGTwitterEngine alloc] initWithDelegate:self]; [twitterEngine setUsername:@"yourusername" password:@"yourpassword"]; [twitterEngine getRepliesStartingAtPage:0]; |
And just implement the callback to get the responses. All responses are nicely packed within an NSArray. Each element is a NSDictionary.. real nice. Oh and for testing NSLog will just spit everything out for your convenience
Here is my code to show the results in a TableView
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(data==nil) { NSLog(@"Returning 0"); return 0; } else { NSLog(@"Returning count %d",[data count]); return [data count]; } } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *txt=@"Nothing.."; if(data!=nil) { NSDictionary *dict=(NSDictionary*)[data objectAtIndex:indexPath.row]; txt=[dict objectForKey:@"text"]; } static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.text=txt; } // Set up the cell... return cell; } - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier{ //NSLog(@"Satuses Received %@:%@",identifier,statuses); if(data!=nil) { [data release]; } data=[[NSMutableArray arrayWithArray:statuses] retain]; UITableView *tableView=(UITableView*)self.view; [tableView reloadData]; NSLog(@"Reloading data"); } |
The idea is to build a good, free version for the iPhone.
Related posts:
- How to use sqlite with UITableView in iPhone SDK Hi All, I have been creating an App using TableView...
- Use NSDateFormatter To Create A Countdown App On iPhone Use NSDateFormatter to extract Date components and use it to...
- Encrypting / Decrypting / Base64 Encode / Decode in iPhone Objective-C I went through websites to find good tricks to send...
- How to use SBJSON and TouchJSON In this post I show how to use the two...
- iPhone SDK 3.0 – Playing with Map Kit – Part 3 This is the 3 part of me Playing with Map...
Related posts brought to you by Yet Another Related Posts Plugin.























4 Responses
Hello,
Nice tutorial, but where can I get this API ? I’ve downloaded his files via svn checkout, but the projects are only for MAC OS X. Please help me, I am really excited about this twitter tutorials series for the iPhone.
Thanks !
@Joao: You will need to move all the files to your iPhone project. Its detailed in the ReadMe file when you use SVN to checkout the latest code
great tutorial but should be have source code sample for download (i just iPhone dev). thank you
can you link me to some demo source code for this?