• 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: Core Data/Cocoa Bindings: best practice for using strings in code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data/Cocoa Bindings: best practice for using strings in code?


  • Subject: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • From: Fritz Anderson <email@hidden>
  • Date: Wed, 13 Jul 2005 21:26:29 -0500

On 13 Jul 2005, at 6:29 PM, Jed Soane wrote:

When we declare the keys as constant strings we get warnings, which make compiling with "treat warnings as errors" impossible to use. For example, the code:

const NSString* CLIP_NAME_KEY = @"clipName";

[clip setValue:clipName forKey:CLIP_NAME_KEY];

causes this error:

ClipList.m:638: warning: passing argument 2 of 'setValue:forKey:' discards qualifiers from pointer target type

Does anyone have any ideas to get around the warning (with removing the const modifier or disabling the warning:)

You've misplaced the const modifier. const NSString * is a pointer to a constant NSString, which isn't what you really mean -- NSString enforces its own immutability, and the C-level immutability of the underlying struct is not of interest to you. What you mean is a constant pointer to an NSString, or NSString * const:


    NSString * const    CLIP_NAME_KEY = @"clipName";

This enlists the compiler in ensuring CLIP_NAME_KEY doesn't get assigned to (at least directly), which is something you do care about, and is within the competence of the compiler.

You should have no warnings using such a constant in setValue:forKey:.

    -- F

_______________________________________________
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


References: 
 >Core Data/Cocoa Bindings: best practice for using strings in code? (From: Michael McCracken <email@hidden>)
 >Re: Core Data/Cocoa Bindings: best practice for using strings in code? (From: Óscar Morales Vivó <email@hidden>)
 >Re: Core Data/Cocoa Bindings: best practice for using strings in code? (From: Jed Soane <email@hidden>)

  • Prev by Date: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • Next by Date: Re: How to get container when overriding NSCreateCommand
  • Previous by thread: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • Next by thread: NSNotificationCenter possible memory leak? [for memory geek]
  • Index(es):
    • Date
    • Thread