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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:07:58+00:00 2026-05-26T21:07:58+00:00

I have a loop for checking if a file extension is on an array:

  • 0

I have a loop for checking if a file extension is on an array:

NSArray* validExtensions = [NSArray arrayWithObjects:@"jpg", @"jpeg", @"png", @"gif", nil];
for (NSString *ext in validExtensions) {
        NSLog(@"filePath: %@\n extension:%@", ext, filePath.pathExtension);
        if ([ext isEqualToString:[self.filePath pathExtension]]) {
            PhotoDetailView *detView = [[PhotoDetailView alloc] initWithNibName:@"PhotoDetailView" bundle:nil];
            detView.image = [UIImage imageWithContentsOfFile:self.filePath];
            [self.navigationController pushViewController:detView animated:YES];

        } else {
            DetailView *theDetail = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
            theDetail.title  = self.fileName;
            self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"My Files" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
            theDetail.textString = self.filePath;
            [self.navigationController pushViewController:theDetail animated:YES];

        }
    }

For some reason, if after the if and else i put break; it just matches jpg entry in the array. If I remove it, I get odd things about nested animations in the log, and multiple views get pushed:

  • Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
  • Unbalanced calls to begin/end appearance transitions for .
  • nested push animation can result in corrupted navigation bar

What am I doing wrong?

  • 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-26T21:07:58+00:00Added an answer on May 26, 2026 at 9:07 pm

    I’m not sure what you expected when using the break inside a for loop, except that it should break the loop (exit without continuing on to the next item). So … the first time through is with your first element (@”jpg”), where it does something then stops.

    Also, your code doesn’t do at all what you said it’s doing. You said, “I have a loop for checking if a file extension is on an array” but your code actually creates an array of file extensions and tries to perform navigation for each one.

    Unless I’ve missed your point, I don’t think you want a for loop. I think you want to get your extension from wherever you need it (some chosen file name?), then just ask the validExtensions array if it contains your file’s extension:

    if ([validExtensions containsObject:someExtension])
    {
      // navigate to the photo detail / @"PhotoDetailView" view
    } else {
      // navigate to the detail / @"My Files" view
    }
    

    The key difference is you’re now asking the array if it contains an object (extension) versus looping the array, locating a match, and trying to break there. That’s your design error.

    Your bug (what’s triggering multiple navigations and their associated log entries) is in the fact that you’re hitting every single valid extension, navigating to either the photo detail view if it matches your file extension, or your “My Files” view if not … and you’re doing this for every entry in the valid extensions array, resulting in four navigations.

    If I’ve not gotten it right, please update your question to clarify your overall goal.

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

Sidebar

Related Questions

I have a loop that reads each line in a file using getline() :
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that is doing some error checking in my PHP code.
I have loop designed to validate the user input on a question, it was
I have a loop on page to update an access database that takes 15-20
I have a loop for(aI = antiviral_data.begin(); aI != antiviral_data.end();) { for(vI = viral_data.begin();
I have a loop like this: for i=1:no %some calculations fid = fopen('c:\\out.txt','wt'); %write
I have a loop MC which will be duplicate to stage several times according
I have a loop that runs through a variety of websites and I'd like
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });

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.