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

The Archive Base Latest Questions

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

Work got in the way of learning Objective C but i’m back at it

  • 0

Work got in the way of learning Objective C but i’m back at it now and this has been driving me crazy.

This is my code:

i=0;
    for (i=0;[photoList count]; i++) {
        NSLog(@"%i",i);
        NSLog(@"%@",[photoList objectAtIndex:i]);
        NSString *fileName = [photoList objectAtIndex:i];
        sendImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
        UIImageWriteToSavedPhotosAlbum(sendImage,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),NULL);}

photoList is just an NSArray like so, except with 24 objects:

NSArray* photoList = [NSArray arrayWithObjects:@"Photo 1.jpg",
    @"Photo 2.jpg",
    @"Photo 3.jpg",
    @"Photo 4.jpg",nil];

It works… It copies the photos to the camera roll… and then crashes with

2010-07-24 19:34:36.116 iCardz2go Poindexter[29662:207] * Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[NSArray objectAtIndex:]: index 24 beyond bounds [0 .. 23]’

I’ve tried various configurations such as

for (i=0;1<23; i++)

only to get
2010-07-24 19:51:01.017 iCardz2go Poindexter[29908:207] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil’

So it’s reading the nil and passing it.

I know its going to be something real simple that I’ve forgotten. Why doesn’t it jump out the loop at Photo 23 (the count)?

Your help is greatly appreciated!
P

  • 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-15T22:49:05+00:00Added an answer on May 15, 2026 at 10:49 pm

    For loops in C and Objective-C look like this:

    for (initialization; condition; increment) {
        // body
    }
    

    initialization is where you set up the loop; it’s where you tell it what to start with. condition is tested for each iteration, including the first; if the condition evaluates to true, the body of the loop is executed. At the end of each iteration, increment is evaluated.

    So:

    for (int i = 0; i < 10; i++) {
        printf("%i\n", i);
    }
    

    Will print the numbers 0 through 9. What you probably want for yours is:

    NSUInteger count = [photoList count];
    for (NSUInteger i = 0; i < count; i++) {
        NSString *fileName = [photoList objectAtIndex: i];
        sendImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: fileName ofType: nil]];
        UIImageWriteToSavedPhotosAlbum(sendImage, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), NULL);
    }
    

    Note the assignment of count outside the loop; it’s simply an optimization so the loop doesn’t have to send an extra message for each iteration (you could just as easily do i < [photoList count].)

    Does that help?

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

Sidebar

Related Questions

Has anybody got this to actually work? Documentation is non existent on how to
There's got to be an easy way to do this, but I cannot find
Here's what I got so far (that doesn't work). At this point I thought
I'm trying to code a exe packer/protector as a way of learning more about
I've got a code work flow dependent on pulling changes from a repo clones
I'm trying to automate many repetitive tasks at work and this small problem got
Update: We are still using XP at work and I got my solution working,
I got the acts_as_taggable_on_steroids plugin to work fine. The tag_cloud method in my view
I recently got involved in a Java project at work: we're using MyEclipse for
I somehow got lumbered with deploying SharePoint at work. I hate it, even the

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.