discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with Replacing a String is a NSMutableString


From: Charles philip Chan
Subject: Re: Problems with Replacing a String is a NSMutableString
Date: Thu, 24 Jul 2008 09:30:08 -0400
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

David Chisnall writes:

> I think the problem is that you are misunderstanding the Objective-C
> type system. The type of an object is a property of the object itself,
> not of the label of the object (as it is in languages like C+ +,
> modulo structural typing).

Yes. This was indeed my problem.

> You can not modify the key of an item in an NSDictionary, because that
> would alter the mappings without NSDictionary knowing that they had
> altered. When you later did objectForKey: on the dictionary,
> NSDictionary would call -hash on the key you passed in. It would then
> look in the bucket associated with this hash and fail to find the key,
> because it put the key in the bucket corresponding to the return value
> of -hash when it was entered. The documentation on NSObject tells you
> that the return value from -hash may not change when an object is in a
> collection.

Now I am clear on that.

> Looking at your code, it seems that you don't actually want to change
> the key in the dictionary, you want to change a copy of it.

Yes. This is where I misunderstood David Ayers.

> For tracking down this kind of bug (and ensuring it doesn't get
> reintroduced), you might find this macro that I use with Etoile
> useful:

Thanks.

With you help, I got it working. The only problem is that I still think
that there is a bug with "replaceOccurrencesOfString: withString:". I
tried it with one of Nicola's tutorials and as with my code, I got a:

,----
| : Uncaught exception NSInvalidArgumentException, reason: Can not
| determine type information for -[GSMutableString
| replaceOccurrencesOfString:withString:]
| Aborted
`----

However, once I replace it with the non-standard "replaceString:
withString:", it worked.

Thank you everyone for your help.

Charles

Attachment: pgplROWtvOx09.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]