Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 709091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:27:54+00:00 2026-05-14T04:27:54+00:00

First, I’m using an NSURLConnection to download JSON data from twitter. Then, I’m using

  • 0

First, I’m using an NSURLConnection to download JSON data from twitter. Then, I’m using a second NSURLConnection to download corresponding user avatar images (the urls to the images are parsed from the first data download).

For the first data connection, I have my TwitterViewController set as the NSURLConnection delegate. I’ve created a separate class (ImageDownloadDelegate) to function as the delegate for a second NSURLConnection that handles the images. After the tweets are finished downloading, I’m using this code to get the avatars:

for(int j=0; j<[self.tweets count]; j++){
    ImageDownloadDelegate *imgDelegate = [[ImageDownloadDelegate alloc] init];

    Tweet *myTweet = [self.tweets objectAtIndex:j];
    imgDelegate.tweet = myTweet;
    imgDelegate.table = timeline; //to reload the data

    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:myTweet.imageURL]
                                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                              timeoutInterval:60];
    imgConnection = [[NSURLConnection alloc] initWithRequest:request delegate:imgDelegate];
    [imgDelegate release];  
}

So basically a new instance of the delegate class is created for each image that needs to be downloaded. Is this the best way to go about this? If I were to create only one instance of the delegate class there’s no way to figure out which image is associated with which tweet, correct? Nor would I be able to figure out the exact order in which the images are being downloaded.

The algorithm works fine… I’m just wondering if I’m going about it the most efficient way .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:27:55+00:00Added an answer on May 14, 2026 at 4:27 am

    Put image downloads into something like an NSOperationQueue.

    When the image download is done, save it to the caches directory, then send out a notification containing the original image URL, and the filename the image is now located at.

    Anything that wants the image can listen for the notification. If nothing cares anymore (say cells that have scrolled off the screen) then they will have unsubscribed from notifications, so the image will just sit there until the system cleans out your cache directory…

    It’s also trivial with this system to check and see if an image already exists on disk before you download it, just keep somewhere a mapping of URL’s to filenames.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First i selected images from photo library to ALAsset Library and after that i
First things first, I'm aware of this question: Gearman: Sending data from a background
first take a look on this picture from localScope app : i have 2
First off, I'm coming (back) to Java from C#, so apologies if my terminology
First, some context: I'm a Python developer who has written a medium-sized application using
First, I am a SQL noob, second if there is a better solution that
first, sorry for my bad English. I try to rewrite url generated from Form
First off I have an app that provides the user information about the amount
We're building an app, our first using Rails 3, and we're having to build
First Im a noob in LINQ ! Then, the thing is that I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.