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

  • Home
  • SEARCH
  • 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 6815551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:49:15+00:00 2026-05-26T20:49:15+00:00

I know there are some solutions out there for saving and loading images on

  • 0

I know there are some solutions out there for saving and loading images on your iPhone. However none have quite worked for me.

For example, the link below has a great code chunk which lets you load and save a UIImage with a unique key, but I can’t work out how to tell when loading an image using this code if an image under that key already exists or not.

http://www.friendlydeveloper.com/2010/02/using-nsfilemanager-to-save-an-image-to-or-loadremove-an-image-from-documents-directory-coding/

//saving an image
- (void)saveImage:(UIImage*)image:(NSString*)imageName {
     NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
     NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
     NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
     NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
     [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
     NSLog(@"image saved");
}

//removing an image
- (void)removeImage:(NSString*)fileName {
     NSFileManager *fileManager = [NSFileManager defaultManager];
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
     NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", fileName]];
     [fileManager removeItemAtPath: fullPath error:NULL];
     NSLog(@"image removed");
}

//loading an image
- (UIImage*)loadImage:(NSString*)imageName {
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
     NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]];
     return [UIImage imageWithContentsOfFile:fullPath];
}

If you could help me work out that out it would be really appreciated. I need to save several images, and load them depending on if a given key already exists or not.

  • 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-26T20:49:16+00:00Added an answer on May 26, 2026 at 8:49 pm

    if u want to get images with unique key, try using UUID. This will always give u image with unique key..For example here is an example of using UUID..

    - (NSString *)pathForImageFileWithPrefix:(NSString *)Prefix
    {
        CFUUIDRef   uuid;
        CFStringRef uuidStr;
        uuid = CFUUIDCreate(NULL);
        uuidStr = CFUUIDCreateString(NULL, uuid);
        NSData *imageData = UIImageJPEGRepresentation(chosenImage, 1.0);
        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
        NSString* documentsDirectory = [paths objectAtIndex:0]; 
        result = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.png",Prefix, uuidStr]];
        [imageData writeToFile:result atomically:NO];
        CFRelease(uuidStr);
        CFRelease(uuid);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I know there's some close duplicates out there, but none of them were able
I know there are multiple solutions online, but some are for windows, some are
Simple query, possibly impossible but I know there are some clever people out there
I know there have been some similar questions to this, but they haven't helped
I would like to know if maybe there are some good solutions to handling
I know there's some JAVA_OPTS to set to remotely debug a Java program. What
I know there are some ways to get notified when the page body has
I know there is some syntax with ? to optionally render attribute. But I
As far as I know there's some kind of Linux in the Chrome OS
Possible Duplicate: Reading/Writing MS Word files in Python I know there are some libraries

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.