• 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: replaceOccurrencesOfString not recognized?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: replaceOccurrencesOfString not recognized?


  • Subject: RE: replaceOccurrencesOfString not recognized?
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Wed, 10 Sep 2003 10:25:53 -0400

> NSMutableString *siteSearchSyntax = [[NSUserDefaults
> standardUserDefaults] objectForKey:selectedItem];

Defining your pointer as a pointer to a mutable string is not good enough.
You also have to make sure that the thing you are pointing to is, in fact, a
mutable string. When you create a mutable string from scratch, you do this
with alloc/init. If you want to use mutable methods on an immutable string,
use the immutable string to create a mutable one. I would do:

NSMutableString *siteSearchSyntax = [[[[NSUserDefaults standardUserDefaults]
objectForKey:selectedItem] mutableCopy] autorelease];

but there are many ways to skin that cat.

One thing that really slowed me down at first is that it is perfectly
acceptable for a method that says it will return an immutable object to
actually return a mutable object. Every once in a while you may be able to
get away with calling a mutable method on what is allegedly an immutable
object. God help you if it's the first thing you try in Cocoa, because it
will take you a long time to unlearn. The only way to _guarantee_ that you
can mutate the string is to create a mutable string based on the immutable
one.

Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >replaceOccurrencesOfString not recognized? (From: Chris Garaffa <email@hidden>)

  • Prev by Date: Re: Multiple Windows and Cocoa
  • Next by Date: Re: Async output ready notification for file descriptors
  • Previous by thread: Re: replaceOccurrencesOfString not recognized?
  • Next by thread: Re: "Borrowing" images from applications with *.rsrc files
  • Index(es):
    • Date
    • Thread