• 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: Óscar Morales Vivó <email@hidden>
  • Date: Wed, 13 Jul 2005 22:23:53 -0400

Ah the wonders of C++ constness...

You really can't declare a const Obj-C object (it's pretty much a C++ thing). If you want to declare that the pointer itself can't be modified, you need to do the type the following:

NSString *const CLIP_NAME_KEY = @"clipName"

Not sure if you need C++ to compile all that (in which case the code file will need to be .mm aka Obj-C++) or if C already accepts it.

Hope that helps.

On Jul 13, 2005, at 19:29 , Jed Soane wrote:

This raises another question I've been meaning to ask. In our code we have an annoying problem. 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:)

Cheers
Jed


On Jul 14, 2005, at 8:57 AM, Óscar Morales Vivó wrote:

I think the usual recommendation is to use constant NSString objects. Put them in the code file, and declare them as 'extern' in the header file if you need to. Examples from my code:

In header OMVPerson.h:

extern NSString *OMVPersonParentsKey;

In code file OMVPerson.m:

NSString *OMVPersonParentsKey = @"parents";



_______________________________________________ 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: 'Touching' managed objects properties.
  • Next by Date: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • Previous by thread: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • Next by thread: Re: Core Data/Cocoa Bindings: best practice for using strings in code?
  • Index(es):
    • Date
    • Thread