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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:59:01+00:00 2026-05-27T17:59:01+00:00

i know many solutions are available here for this problem but I am stuck

  • 0

i know many solutions are available here for this problem but I am stuck on a single line which runs sometime successfully n crashes sometimes, i really dont know why this is happening…..

here is my code of posting mail in which i m getting the error -[__NSCFDictionary rangeOfString:]: unrecognized selector sent to instance

and here is my code of the method which is called on button pressed.

NSString* ingredientLine = [arrayOfIngredientList objectAtIndex:i];

NSArray* split ;

NSRange range = [ingredientLine rangeOfString:@"~"];

if (range.length > 0)
{
    split = [ingredientLine componentsSeparatedByString:@"~"];

    if( [split count] > 1 )
    {
        float amount = [[split objectAtIndex:0] floatValue];

        float actualAmount = amount*((float)recipeServings/(float)4);

        //parse the float if its 1.00 it becomes only 1

        NSString* amnt = [NSString stringWithFormat:@"%.1f", actualAmount];

        NSArray* temp = [amnt componentsSeparatedByString:@"."];

        if([[temp objectAtIndex:1] isEqualToString: @"0"])

            amnt = [temp objectAtIndex:0];

        if( actualAmount == 0.0 )

            amnt = @"";

        [amnt stringByReplacingOccurrencesOfString:@".0" withString:@""];

        NSLog(@"Amount is : %@",[split objectAtIndex:1]);

        strAmount = [@"" stringByAppendingFormat:@"%@ %@",amnt,[split objectAtIndex:1]];

        NSLog(@"Ingredient is : %@", strAmount);

        strIngedient = [split objectAtIndex:2];

    }
    else //ingredients header
    {
        //[[cell viewWithTag:10] setHidden:YES];
        strIngedient = [split objectAtIndex:0];
    }
}
else 
{

}

strIngredientsInfo = [strIngredientsInfo stringByAppendingFormat:@"%@ - %@ </br>",strAmount,strIngedient];

App crashes due to

    NSArray* split ;

NSRange range = [ingredientLine rangeOfString:@"~"];

if (range.length > 0)
{
    split = [ingredientLine componentsSeparatedByString:@"~"];
    }

Please Help.

Please Suggest why it is crashing ???? 🙁

  • 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-27T17:59:02+00:00Added an answer on May 27, 2026 at 5:59 pm

    It is happening because sometimes this piece of code:

    [arrayOfIngredientList objectAtIndex:i]
    

    returns an instance of an NSDictionary instead of the NSString you are expecting. It does this because somewhere beforehand you have stored an NSDictionary in that array.

    So, I don’t know how big that array is and whether it’s practical to print its entire contents out to see what’s happening, but here’s something to help you debug. In the piece where it’s crashing, change it to this:

    if ( ! [ingredientLine respondsToSelector:@selector(rangeOfString:)] ) {
        NSLog(@"ingredientLine is not an NSString! It is a: %@", ingredientLine);
    } else {
        NSRange range = [ingredientLine rangeOfString:@"~"];
    }
    

    You can also put a breakpoint on the NSLog line to see what’s happening. Note that this will stop your crashes, but it does not fix the underlying problem. This is just a suggestion to help you debug the real issue, which is that somewhere further up the line you are putting NSDictionary instances in your arrayOfIngredientList.

    EDIT: Some explanation of what’s happening here might help you. The if statement checks to see whether the object pointed to by ingredientLine does not respond to the message rangeOfString:. Even though you’ve declared ingredientLine as an NSString *, you can easily assign it to an instance of a completely different class, in which case it won’t be an NSString instance anymore and it won’t be able to respond to NSString‘s messages. Note that you could also say:

    `if ( ! [ingredientList isKindOfClass:[NSString class]] )`
    

    Which would do the same job here. However I used respondsToSelector: as it’s a very useful message to know about in Objective C.

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

Sidebar

Related Questions

I know many people experience this problem, but the solutions I found online do
I know this question is posted many times, but I want to ask about
Firstly I know that there are many question and solutions to correct thread marshalling
I know many:many isn't supported in Linq2Sql but I am working on a workaround
I bet this has been answered many times over, but... For a simple situation
I frequently need to make many replacements within files. To solve this problem, I
I know many people who use computers every day, who do not know how
I would like to know many minutes between 2 dates? Example : Now -
I use VIM editor for PHP, i know many people will point to PDT
Does any Common Lisp (builtin) function return more than 2 values? I know many

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.