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 3341008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:40:24+00:00 2026-05-18T00:40:24+00:00

Hi all i am trying to save image in the bundle which i have

  • 0

Hi all i am trying to save image in the bundle which i have currently on my view,but the problem is that i can only save one image,if i want to save the another image it replaces the old.I am not getting how to save the multiple images in the bundle then.
Here is my code.

- (void)writeImageToDocuments:(UIImage*)image 
{
    NSData  *png = UIImagePNGRepresentation(image); 
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSError *error = nil;
    [png writeToFile:[documentsDirectory stringByAppendingPathComponent:@"image.png"] options:NSAtomicWrite error:&error];


}

Please Help me out, how to save multiple images, files e.t.c in bundle

Thanks in advance

  • 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-18T00:40:25+00:00Added an answer on May 18, 2026 at 12:40 am

    You’re not saving into a bundle, you’re saving into your app’s documents directory. There’s no bundle aspect to it.

    You’re using the filename @”image.png” for every file that you save. Hence each new write overwrites the old one. In fact, you write each file twice. To save multiple files, use different file names.

    It’s also bad form to pass a numeric constant as the ‘options:’ parameter of NSData writeToFile:options:error: (or indeed, any similar case). The value ‘3’ includes an undefined flag, so you should expect undefined behaviour and Apple can legitimately decline to approve your application. Probably you want to keep the NSAtomicWrite line and kill the one after it.

    If you’re just looking to find the first unused image.png filename, the simplest solution would be something like:

    int imageNumber = 0;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *pathToFile;
    
    do
    {
        // increment the image we're considering
        imageNumber++;
    
        // get the new path to the file
        pathToFile = [documentsDirectory stringByAppendingPathComponent:
                                               [NSString stringWithFormat:
                                                        @"image%d.png", imageNumber]];
    }
    while([fileManager fileExistsAtPath:pathToFile]);
    /* so, we loop for as long as we keep coming up with names that already exist */
    
    [png writeToFile:pathToFile options:NSAtomicWrite error:&error];
    

    There’s one potential downside to that; all the filenames you try are in the autorelease pool. So they’ll remain in memory at least until this particular method exits. If you end up trying thousands of them, that could become a problem — but it’s not directly relevant to the answer.

    Assuming you always add new files but never remove files then this problem is something you could better solve with a binary search.

    File names searched will be image1.png, image2.png, etc.

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

Sidebar

Related Questions

I'm trying to save some data into an array but unfortunately all the data
I'm currently trying to crop an image, and then save the new image. I
I met this message of error while trying to save an image which has
I'm trying to save a Layout into an Image in the SDCard but I
i am trying to save image outside of my web app directory. i have
im trying to save a row in my settings table, it works all fine
I'm trying to query a table, fetch all records, and save the result as
I have been trying all afternoon to get the jQuery Sifr Plugin ( http://jquery.thewikies.com/sifr/
I have been trying all day to get some data properly formatted in a
I have been struggling all afternoon trying to get a simple mailto: tag to

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.