• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: multiple declarations for method `length' ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple declarations for method `length' ?


  • Subject: Re: multiple declarations for method `length' ?
  • From: j o a r <email@hidden>
  • Date: Thu, 30 Dec 2004 19:16:28 +0100

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: multiple declarations for method `length' ?
      • From: John Stiles <email@hidden>
References: 
 >multiple declarations for method `length' ? (From: Mark Dawson <email@hidden>)

  • Prev by Date: multiple declarations for method `length' ?
  • Next by Date: Shark: Attempt to insert nil key?
  • Previous by thread: multiple declarations for method `length' ?
  • Next by thread: Re: multiple declarations for method `length' ?
  • Index(es):
    • Date
    • Thread