Re: Core Data/Cocoa Bindings: best practice for using strings in code?
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