FROM : John Stiles
DATE : Thu Dec 30 19:36:27 2004
On Dec 30, 2004, at 10:16 AM, j o a r wrote:
> Please don't cross-post!
>
> On 2004-12-30, at 19.05, Mark Dawson wrote:
>
>> When compiling this Obj-C line in XCode 1.5, I get the following
>> warning:
>>
>> LengthParser.m:295: warning: multiple declarations for method `length'
>>
>> short decimalLen = [[[NSUserDefaults standardUserDefaults]
>> objectForKey:NSDecimalSeparator] length];
>>
>> What does this mean? It seems to run OK, producing the result (1 for
>> US system) that I'd expect…
>
> If you check NSDictionary you'll find that:
>
> - (id)objectForKey:(id)aKey
>
> ...it returns an "id" object. In other words, the compiler don't know
> what type of object it is. When you call the method "length" on that
> object, the compiler needs to guess what implementation to use. If
> there is only one such method it's easy, but if there are several it's
> not. You can help the compiler by casting:
>
> NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:
> NSDecimalSeparator];
> short decimalLen = [str length];
>
> or
>
> short decimalLen = [(NSString *)[[NSUserDefaults standardUserDefaults]
> objectForKey:NSDecimalSeparator] length];
>
> j o a r
I thought one of the huge advantages of message-passing over function
calls was that you could send messages to "id" objects and objc_send
would sort out the details.
DATE : Thu Dec 30 19:36:27 2004
On Dec 30, 2004, at 10:16 AM, j o a r wrote:
> Please don't cross-post!
>
> On 2004-12-30, at 19.05, Mark Dawson wrote:
>
>> When compiling this Obj-C line in XCode 1.5, I get the following
>> warning:
>>
>> LengthParser.m:295: warning: multiple declarations for method `length'
>>
>> short decimalLen = [[[NSUserDefaults standardUserDefaults]
>> objectForKey:NSDecimalSeparator] length];
>>
>> What does this mean? It seems to run OK, producing the result (1 for
>> US system) that I'd expect…
>
> If you check NSDictionary you'll find that:
>
> - (id)objectForKey:(id)aKey
>
> ...it returns an "id" object. In other words, the compiler don't know
> what type of object it is. When you call the method "length" on that
> object, the compiler needs to guess what implementation to use. If
> there is only one such method it's easy, but if there are several it's
> not. You can help the compiler by casting:
>
> NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:
> NSDecimalSeparator];
> short decimalLen = [str length];
>
> or
>
> short decimalLen = [(NSString *)[[NSUserDefaults standardUserDefaults]
> objectForKey:NSDecimalSeparator] length];
>
> j o a r
I thought one of the huge advantages of message-passing over function
calls was that you could send messages to "id" objects and objc_send
would sort out the details.
| Related mails | Author | Date |
|---|---|---|
| Mark Dawson | Dec 30, 19:05 | |
| j o a r | Dec 30, 19:16 | |
| John Stiles | Dec 30, 19:36 | |
| mmalcolm crawford | Dec 30, 19:45 | |
| Charlton Wilbur | Dec 30, 19:57 | |
| glenn andreas | Dec 31, 04:23 | |
| Sherm Pendley | Dec 31, 22:10 |






Cocoa mail archive

