Re: KVC and KVO for arrays
Re: KVC and KVO for arrays
- Subject: Re: KVC and KVO for arrays
- From: "John Dann" <email@hidden>
- Date: Thu, 14 Feb 2008 14:05:29 +0000
> (2) If I misspell the key as "atendees", I won't get any compile-time
> warning, just an exception at runtime.
This is an easy one to fix. Just add:
#define ATTENDEES_KEY @"attendees"
above your implementation, along with your #import statements, or you
can define an external NSString as such:
// myclass.h
extern NSString *AttendeesKey;
//myclass.m
NSString *AttendeesKey = @"attendees";
Then in you code, calls like
[self setValue:anObject forKey:ATTENDEES_KEY]; // case 1
or
[self setValue:anObject forKey:AttendeesKey]; // case 2
will both get compile-time checked and properly syntax highlighted.
This has the added bonus of not having to do a find-replace on your
whole code if you change the name of an ivar, and if you've defined the
string wrongly then you don't have far to look to find your spelling
mistake
I'm not massively experienced in C, started in FORTRAN and came into
Objective-C this year, can anyone tell me how the two versions differ
and if adopting one over the other will have any effect on my code
later? Much of the Apple code I've seen use #define statements, but
I've seen the NSString elsewhere like in Hillegass's book.
Jon
This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.
Please be aware that, under the terms of the Freedom of
Information Act 2000, Swansea NHS Trust may be required to make
public the content of any emails or correspondence received. For
further information on Freedom of Information, please refer to the
Swansea NHS Trust website at www.swansea-tr.wales.nhs.uk
_______________________________________________
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