RE: componentsSeparatedByString:
RE: componentsSeparatedByString:
- Subject: RE: componentsSeparatedByString:
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Wed, 29 Oct 2003 14:06:08 -0500
>
I'm putting some items of the array returned by -[NSString
>
componentsSeparatedByString:] into another array to read them back
>
later. However, after having used these NSStrings a couple of times,
>
they become empty (they are still valid NSString objects, but empty
>
strings).
Some code would help.
>
If I inspect them, it appears that they are instances of
>
NSBigMutableString (which I guess is part of the NSMutableString class
>
cluster). I don't use mutable strings in that part of my application,
>
so I can't be the one altering their content. I tried to -[copy] them
>
before putting them in my array, and it solved the problem.
>
My deduction: the strings returned by -[NSString
>
componentsSeparatedByString:] are mutable strings (strange, but
>
alright) which are somehow modified later (for some definition of
>
later...), and *not by me*.
First, you can't count on getting a mutable string back. It might be
mutable because NSString decides that a mutable string is best in some
particular set of circumstances. Even if you know how NSString makes that
decision today, the method could change in a later version of the framework.
So don't assume.
Second, it's extremely unlikely that Cocoa is changing around your strings
behind your back. I've never seen it, and that would be a bug of the first
order so it would be fixed pretty darn quick.
Are you really sure you are accessing the same strings every time? Are you
really sure they don't start out empty? Try to figure out exactly when the
value changes (using the debugger of course).
>
Has anyone ever experienced that? It looks like it only happens if
>
-[NSString componentsSeparatedByString:] returns a singleton.
What do you mean by "returns a singleton"? It always returns a regular
instance of NSArray (or a subclass).
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.