Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Image Caching Tutorial

2»

Replies

  • davidlxkdavidlxk Posts: 43Registered Users
    edited December 2011
    check this link out on using Grand Central Dispatch and NSCache to improve the performance of Table Views

    Cocoa Touch Tutorial: Using Grand Central Dispatch for Asynchronous Table View Cells | Jeff Kelley?s Blog
    Drop Dem is out now! You should check it out at <a href="http://itunes.apple.com/us/app/drop-dem/id490101113"; target="_blank">http://itunes.apple.com/us/app/drop-dem/id490101113</a><br />
    <br />
    You should follow Drop Dem on Twitter <a href="http://twit
  • AbejundioAbejundio Posts: 1New Users
    edited January 2012
    Dear chewbocka, I appreciate your work relating to Image Caching.Its really nice and helpful tutorial shared by you.I hope you will keep share such stuff in future days.Thanks for sharing such a nice tutorial with us.
  • chanduwtbchanduwtb Posts: 2New Users
    thank you for this tutorial
  • chanduwtbchanduwtb Posts: 2New Users

    I can't get the code to work properly, it might be something to do with

    NSString *filename = [[something unique, perhaps the image name]]


    I put
    NSString *filename = @\";Test\";


    Any ideas?
    I have the same issue....
  • Magnat12Magnat12 UkrainePosts: 3New Users Noob
    edited July 2013
    One suggestion for the image cache name:
    You can generate MD5 string from image URL (URL is always unique for each image :) ) and use it as filename.
    Anyway system correct recognize files without extension (it can be PNG or JPG file).
    This allow very quick search for image in cache - you need to check only one file path:
    Here is example of code inside caching images:
    		
    - (UIImage *)loadImageWithCaching:(NSString *)imageURL
    {
    	// generate hash from image URL
    	// more information here: http://stackoverflow.com/questions/1524604/md5-algorithm-in-objective-c
    	NSString *filename = [self generateMD5FromURL:imageURL];
    	
    	// create full file path
    	NSString *filePath = [SOME_CONSTANT_PATH_TO_CACHE_FOLDER stringByAppendingString:filename];
    	
    	// check is file in cache
    	NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
    	
    	if (!data) {
    		// if not in cache, we just load from URL
    		data = [[NSData alloc] initWithContentsOfURL:imageURL];
    		
    		// and save to disk
    		[data writeToFile:filePath atomically:NO];
    	}
    	
    	// create UIImage object and return it
    	UIImage *image = [[UIImage alloc] initWithData: data];
    	return image;
    }
    

  • Magnat12Magnat12 UkrainePosts: 3New Users Noob
    After this you can play with caching to memory/ background loading/ multithreading/ NSQueue operations and other interesting thing.
  • kevinwallacekevinwallace Posts: 2New Users
    Great tutorial of Image catching you shared here. Its helpful me in my app development. Thank you so much.
  • wizard1966wizard1966 EuropePosts: 1New Users Noob
    Bon,
    A very quick note to say "THANKS" pretty new to OOC but managed to copy and paste this into my code and make it work!! made a real difference to my app!!!
2»
Sign In or Register to comment.