• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problem with rangeOfString debugger warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with rangeOfString debugger warning


  • Subject: Re: problem with rangeOfString debugger warning
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 30 Jul 2015 09:19:34 -0700

> On Jul 30, 2015, at 1:11 AM, 2551 <email@hidden> wrote:
>
> In the docs under ‘Special Considerations’ it says "This method detects all invalid ranges (including those with negative lengths). For applications linked against OS X v10.6 and later, this error causes an exception; for applications linked against earlier releases, this error causes a warning, which is displayed just once per application execution.”
>
> My questions are: what causes this to be an “invalid range” rather than an NSNotFound? And: How do I avoid it when searching for a potentially non-existent string?

You’re confusing -substringWithRange: with -rangeOfSubstring:. The documentation and warning you cite come from the former, but you’re talking about the latter.

As the docs promise, -rangeOfSubstring: will either return a valid range, or {NSNotFound, 0}. What’s probably happening to you is that you called it on a nil string. This means the method isn’t called at all. In most cases messaging nil will return a value of 0 or 0.0 or nil, but struct returns are an exception — the struct will be uninitialized on return, i.e. garbage. (This happens because the Obj-C runtime doesn’t know how big the returned struct is, so it can’t safely fill it with zeros.)

Put an NSAssert(someString!=nil) before the -rangeOfString: call and it should pinpoint when the problem occurs.

—Jens
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: problem with rangeOfString debugger warning
      • From: 2551 <email@hidden>
References: 
 >problem with rangeOfString debugger warning (From: 2551 <email@hidden>)

  • Prev by Date: Re: NSManagedObject, NSString property retain vs copy
  • Next by Date: Re: Regarding these Olivia messages. Can we do something about the list security?
  • Previous by thread: Re: problem with rangeOfString debugger warning
  • Next by thread: Re: problem with rangeOfString debugger warning
  • Index(es):
    • Date
    • Thread