• 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: KVC and KVO for arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC and KVO for arrays


  • Subject: Re: KVC and KVO for arrays
  • From: "Kyle Sluder" <email@hidden>
  • Date: Fri, 15 Feb 2008 12:43:52 -0500

On Fri, Feb 15, 2008 at 5:27 AM, John Dann
<email@hidden> wrote:
>  Ok, sorry, I mean could this come back and bite me if I need to
>  refactor my code in some way?  I was wondering if there was a subtle
>  difference in the way #defines and external variables operate that could
>  cause headaches

Yes.  If you #define a constant NSString, there is no guarantee that
the compiler will coalesce this constant with other identical NSString
constants in other compilation units, meaning you can't do things like
if(param == MyStringConstant).  For example:

// file: MyErrors.h
#define MY_ERROR_DOMAIN @"MyErrorDomain"
extern NSString *MyErrorDomain;  // defined in MyErrors.m

// file: MyObject.m
#import "MyErrors.h"

- (BOOL)performSomeActionWithError:(NSError *)err
{
    if(err != NULL)
        *err = [NSError errorWithDomain:MY_ERROR_DOMAIN
            code:0 userInfo:nil];

    return NO;
}

// file: MyObjectClient.m
#import "MyObject.h"
#import "MyErrors.h"

- (void)doSomething
{
    MyObject *foo = [[MyObject alloc] init];
    NSError *err;
    if([foo performSomeActionWithError:&err] == NO)
    {
        // This is not guaranteed to work!
        // The constant created when MyObject.m is compiled
        // may be distinct from the one created when this file
        // is compiled.
        if([err domain] == MY_ERROR_DOMAIN])
            // do something
    }
}

-- Kyle Sluder
_______________________________________________

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

References: 
 >Re: KVC and KVO for arrays (From: "John Dann" <email@hidden>)
 >Re: KVC and KVO for arrays (From: Nick Toumpelis <email@hidden>)
 >Re: KVC and KVO for arrays (From: "John Dann" <email@hidden>)

  • Prev by Date: Re: Uncaught exceptions thrown by Cocoa documented anywhere?
  • Next by Date: Re: Uncaught exceptions thrown by Cocoa documented anywhere?
  • Previous by thread: Re: KVC and KVO for arrays
  • Next by thread: Re: KVC and KVO for arrays
  • Index(es):
    • Date
    • Thread