0

I have a class extension looking like this:

#import <Cocoa/Cocoa.h>
@interface NSBezierPath (BezierTimerExtension)

@property (strong, nonatomic) NSTimer *timer;
@property (strong, nonatomic) NSColor *color;

- (void)startTimer;
- (void)stopTimer;

@end

#import "NSBezierPathWithTimer.h"

@implementation NSBezierPath (BezierTimerExtension)

- (void)startTimer {
    if (self.timer != nil) {
        [self.timer fire];
    }
}

- (void)stopTimer {
    if (self.timer != nil) {
        [self.timer invalidate];
    }
}

- (NSTimer *)timer {
    return self.timer;
}

- (void)setTimer:(NSTimer *)newTimer {
    _timer = newTimer;
}

- (NSColor *)color {
    return self.color;
}

- (void)setColor:(NSColor *)newColor {
    _color = newColor;
}

@end

The problems are the two setters. Because Xcode says, that he don't know what to do with _timer or _color. When I set the variable with self.timer or self.color, it will create a infinite loop. self->timer and self->color is not working too.

How can I set the property timer and the property color in the setter? Also the getter should not work, as I see now. But thats simply the same problem.

Thanks for the answers iComputerfreak

rmaddy
  • 314,917
  • 42
  • 532
  • 579
iComputerfreak
  • 890
  • 2
  • 8
  • 22
  • You can't really add properties in categories, if you must, the typical way around this is using the obj-c run-time. See this question http://stackoverflow.com/q/8733104/1316346 – Kevin DiTraglia Jun 15 '14 at 16:03
  • @KevinDiTraglia You can add properties, you can't add instance variables. Big difference. – rmaddy Jun 15 '14 at 16:45

0 Answers0