• 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
Setter Declaration for Scalar, with @property --> Silent Runtime Failure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setter Declaration for Scalar, with @property --> Silent Runtime Failure


  • Subject: Setter Declaration for Scalar, with @property --> Silent Runtime Failure
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 19 Nov 2008 20:40:07 -0800

I'm surprised I couldn't find this in the list archives. While remodelling some old code, I got tired of scrolling and decided to replace a couple dozen old accessors with @property and @synthesize. But I inadvertantly left a few of the old getter declarations in the code. Like this one:

#import <Foundation/Foundation.h>

@interface Foo : NSObject {
    NSInteger bar ;
}

@property (assign) NSInteger bar ;

// Whoops, don't need this any more:
- (void)setBar:(NSInteger)someBar ;

@end

@implementation Foo
@synthesize bar ;
@end

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    Foo* foo = [[Foo alloc] init] ;
    foo.bar = 600 ;
    NSLog(@"foo.bar = %d", foo.bar) ;
    [foo release] ;
    [pool drain];
    return 0;
}

Build and run the above project. No warnings, no errors, no exceptions, but the output logs:

   JunkProps[7449:10b] foo.bar = 0

Remove the old getter declaration under // Whoops, and it's fixed:

   JunkProps[7462:10b] foo.bar = 600

If I change 'bar' to be an NSString* instead of an NSInteger, the extra setter does not cause this problem.

I cannot think of any sensible explanation for this.

Jerry



_______________________________________________

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


  • Follow-Ups:
    • Re: Setter Declaration for Scalar, with @property --> Silent Runtime Failure
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: Autorelease Question
  • Next by Date: Re: Outlets / IBOutlet declarations (was Re: Interface Builder &Wiring Objects)
  • Previous by thread: Re: forcing menu validation
  • Next by thread: Re: Setter Declaration for Scalar, with @property --> Silent Runtime Failure
  • Index(es):
    • Date
    • Thread