• 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
Any good advice for naming parameters of init methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Any good advice for naming parameters of init methods?


  • Subject: Any good advice for naming parameters of init methods?
  • From: an0 <email@hidden>
  • Date: Thu, 10 Jul 2008 22:25:05 +0800

I've been always stumbling on the embarrassment of "warning: local
declaration of 'xxx' hides instance variable" for my init methods,
because I really can't figure out a nice naming pattern for parameters
used to assign to instance properties, and I am always apt to write
code like this:
 - (id)initWithURL:(NSString *)url title:(NSString *)title
tags:(NSString *)tags note:(NSString *)note time:(NSString *)time
count:(NSUInteger)count
since it is most natural(to me). Then I just see XCode spew out lots
of annoying warnings like these:
  Line Location Post.m:28: warning: local declaration of 'url' hides
instance variable
  Line Location Post.m:28: warning: local declaration of 'url' hides
instance variable
  Line Location Post.m:29: warning: local declaration of 'title' hides
instance variable
  Line Location Post.m:29: warning: local declaration of 'title' hides
instance variable
  Line Location Post.m:32: warning: local declaration of 'time' hides
instance variable
  Line Location Post.m:32: warning: local declaration of 'time' hides
instance variable
  Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
  Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable


Even though I then follow the general naming rules to prepend an
indefinite article to each singular noun, I still have those plural
nouns sitting there, which now looks this:
 - (id)initWithURL:(NSString *)aUrl title:(NSString *)aTitle
tags:(NSString *)tags note:(NSString *)aNote time:(NSString *)aTime
count:(NSUInteger)aCount
Set aside the oddness of aTime and aCount, my XCode still complain:
  Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
  Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable

Am I supposed to use something like aGroupOfTags instead of just tags?
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Any good advice for naming parameters of init methods?
      • From: Graham Cox <email@hidden>
    • Re: Any good advice for naming parameters of init methods?
      • From: Steve Nicholson <email@hidden>
  • Prev by Date: Re: NSEntityDescription random crash
  • Next by Date: Re: Why can't I name a property `tag'?
  • Previous by thread: Re: NSEntityDescription random crash
  • Next by thread: Re: Any good advice for naming parameters of init methods?
  • Index(es):
    • Date
    • Thread