0

I am using ARC with TWRequest. I have successfully returned a search from twitter and created an array of the results. Here is my code...

NSArray *results = [dict objectForKey:@"results"];


            //Loop through the results
    NSMutableArray *twitterText = [[NSMutableArray alloc] init];

            for (NSDictionary *tweet in results)
            {
                // Get the tweet
                NSString *twittext = [tweet objectForKey:@"text"];

                // Save the tweet to the twitterText array
                [twitterText addObject:twittext];
}
                NSLog(@"MY ************************TWITTERTEXT************** %@", twitterText ); </p>

My question is, I want to use twitterText later in the .m file under cellForRowAtIndexPath but as soon as the loop through (as above) is finished it is being released under ARC. I have set the property as strong in my .h file (as well as declaring it above just prior to the loop). Printing a log straight after the loop through as above prints the twitterText Array fine but the same Log in cellForRowAtIndex path method returns a blank. Any help would be appreciated. Thanks. Alan

Alan
  • 63
  • 7

1 Answers1

0

Alan,

You do not appear to be saving twitterText in any permanent ivar. As the code is written above, ARC properly deallocates twitterText after the log statement.

Hence, just assign twitterText to an ivar in your controller.

Andrew

adonoho
  • 4,339
  • 1
  • 18
  • 22
  • Do you mean create another Array in my .h say, NSArray *twitterTextCopy and then say twitterText = twitterTextCopy in my viewdidload? Thanks – Alan Jul 11 '12 at 08:21
  • Alan, you need to retain `twitterText` by assigning it to a permanent location. These are typically an ivar on an instance. For example, `@property (strong, nonatomic) NSArray *twitterText;` will do the job. Then your assignment is: `self.twitterText = twitterText;`. Andrew P.S. You appear to have some issues with the basics of Objective-C. May I respectfully suggest that you spend some time with Kolchan's or Knaster's books on Objective-C. – adonoho Jul 11 '12 at 12:51
  • Hi Andrew, pls see mt first note above as I have already set @property (strong, nonatomic) NSArray *twitterText; but this has not actually worked. Can I just ask is self.twitterText = twitterText; declared in view did load? Thanks for your help (BTW, I have read Kolchans book, I'll try the other - thanks) – Alan Jul 11 '12 at 13:06
  • Alan, `self.twitterText = twitterText;` is how you use the @property to set the ivar `twitterText` from within the class. Without seeing your class declaration and the `@synthesize`s, I'm at a loss to see what is going on. Andrew – adonoho Jul 12 '12 at 21:46
  • Ok, here goes synthesize dict; synthesize twitterText = _twitterText;from the .h file..... then for my properties(strong) NSDictionary *dict; (strong) CLLocationManager *here; (strong, nonatomic) NSMutableArray *twitterText; – Alan Jul 17 '12 at 16:35