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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:23:06+00:00 2026-05-13T15:23:06+00:00

i’ve written a for loop in Objective-C, This is how my code looks like

  • 0

i’ve written a for loop in Objective-C, This is how my code looks like

NSString *string = [NSString stringWithContentsOfFile=@"/Users/Home/myFile.doc"];
NSString *seperator=@"\n";
NSArray *mainarray = [string componentsSeparatedByString:seperator];
// Since i want to parse each element of mainarray
for(NSString *s in mainarray)
{
  //again parising the string using a new separator
    NSString newseparator = @"=";
    NSArray *subarray = [s componentsSeparatedByString : newseparator];

  //Copying the elements of array into key and object string variables

    NSString *key = [subarray objectAtIndex:0];
    NSLog(@"%@",key);
    NSString *class_name= [subarray objectAtIndex:1];
    NSLog(@"%@",class_name);

   // create an instance for the class_name
      //dont knw how it ll take the value from file and ???  

 //Putting the key and objects values into hashtable 
    NSMutableDictionary = [NSDictionary dictinaryWithObject:class_name forKey:key];
}

Whenever i execute this code this crashes my program saying as, Terminating the app due to uncaught exception NSRangeException

How to know the range of array and how to specify the terminating condition in the for loop???and plz let me knw how to handle this exception???

  • 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-13T15:23:07+00:00Added an answer on May 13, 2026 at 3:23 pm

    I’m surprised that code even compiles. If I remember correctly, it can’t compile unless you have gone to great lengths to turn off a whole bunch of compiler warnings.

    NSString newseparator = @";";
    

    That should give an error write there in that you don’t have the *.

    NSString *key = [subarray objectAtIndex[0]];
    NSString *object = [subarray objectAtIndex[1]];
    

    Neither of these lines of code make any sense.

    It would appear that you haven’t posted the actual code?


    Now, getting back to the exception. A range exception will be tossed if you try to access an item at an index that is outside of the range of indexes available in the array. Thus, if componentsSeparatedByString: returned an array of 0 or 1 elements, then [subarray objectAtIndex: 1]; will cause a range exception to be raised.

    What you don’t want to do is to try and handle the exception using an @catch block. In Cocoa (and iPhone development), exceptions are treated as non-recoverable errors.

    So, instead, use the -count method on NSArray to verify that the array actually contains the # of elements you were expecting. Since you are writing a casual parser, this is probably a good idea as a minimal check of input validity.

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

Sidebar

Ask A Question

Stats

  • Questions 298k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I interpret your question correctly, then the proper way… May 13, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer Use a unique ID. Add an attribute to your Friend… May 13, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer Yes, you can. JQuery validation purely work on the client… May 13, 2026 at 7:36 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.