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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:33:48+00:00 2026-05-25T09:33:48+00:00

I’ve tried checking for an occurrence of a substring in an NSString in two

  • 0

I’ve tried checking for an occurrence of a substring in an NSString in two ways, both have crashed. This is an NSString object I get from one of my NSManagedObject’s properties.

  1. Using NSRange

    NSString *searchString = @"drive";

    NSRange range = [text rangeOfString:searchString options:(NSCaseInsensitiveSearch)];

    if (range.location != NSNotFound) {
    NSLog(@"Found");
    }

  2. Using NSScanner

    NSScanner *scanner = [NSScanner scannerWithString:text];

    NSLog(@"%d",[scanner scanString:searchString intoString:nil]);

Both of these work when text = @”drive” but cause EXC_BAD_ACCESS crashes when the text is “i drive”, or “drive to”. Nothing happens if the text is “idrive” or “driveto”.

Even stranger, sometimes the examples throw NSInvalidArgumentExceptions, saying that I tried to pass an NSCFSet or a DateComponents object to rangeOfString:, neither of which I use in my app.

Any ideas?

  • 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-25T09:33:49+00:00Added an answer on May 25, 2026 at 9:33 am

    If you sometimes get EXC_BAD_ACCESS and sometimes get the message “object-of-type-you-weren’t expecting does not respond to method” the chances are you are not retaining the object for long enough and it is getting deallocated before you get to where you use it.

    If the memory hasn’t been reused when you get there, things will appear to work. If the space has been reused for another object and aligns perfectly i.e. same pointer, you’ll get something like “x does not respond to selector”. If it’s overwritten in such a way that the pointer does not point to a valid object, you’ll get EXC_BAD_ACCESS

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.