Sunday, October 23, 2011

iOS 5 Tweeting Apple Sample Code (Errors?) + How to Parse JSON With NSJSONSerialization

     I was planning on creating an extensive tutorial a couple weeks ago on how to use the Twitter API in iOS 5, but I was running into errors and I thought I would tell you what my errors were and how I resolved them.

Apple Sample Code: here

1. I downloaded the Tweeting Apple sample code and ran the package and noticed they had an example on how to download public timelines in JSON format using the new TWRequest class.


2. In the sample code they used the NSJSONSerialization to create the publicTimeline NSDictionary. I tried to create a new array NSArray *keys = [publicTimeline allKeys]; and the program would crash.

This is the error:





3. Naturally, the first thing I did was ask my friend who works at Apple (comparative advantage) and he really didn't know what was going on so I was stuck and trying different things for about a week. I then did some searching and reading in forums and someone was having a similar error with NSMutableArrays being converted into NSCFArrays and then someone on stack overflow suggested creating a new array with an array and it sparked an idea for me to do the same.

Note: I searched the Apple Developer Forums as well and I couldn't find a solution so I thought I should post it here.


4. Anyways, long story short I figured out how to do it. Just create an array with the publicTimeline NSDictionary. Each object in the NSArray is an NSDictionary of statuses and using the key "text" you can retrieve the text of each tweet.






I have to finish this post later since I have midterms this week...  In the meantime you can download the project below.

Full Project Here: here

Correction: What you can do is just create an array initially.



2 comments :

Lauraine said...

Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
html5 player| html5 video player

I'm so kind. said...

I'm still getting

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SBJsonUTF8Stream getRetainedStringFragment:]: unrecognized selector sent to instance

and stop at SBJsonTokeniser.m =((

if (![_stream getRetainedStringFragment:&string])