RE: replaceOccurrencesOfString not recognized?
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.