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
pgpADDEuJvykl.pgp
Description: PGP signature
_______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
