0

I have a problem with get property. When I pass _videoRect to the drawArea function that nothing happens. But if I am change self.videoRect that work perfect.

My code:

@property (nonatomic, assign) BOOL isRecording;
@property (nonatomic) NSValue* videoRect;

@implementation Interactor
@synthesize videoRect = _videoRect;

- (id)init {
    _isRecording = NO;

    [self createVideoObserver];

    return self;
}

- (void)record {

    _isRecording = !_isRecording;

    if (!_isRecording) {
        [self stop];
        [_presenter animateRecordButton:_isRecording];
    } else {
        [self drawArea:&(_videoRect) completion:nil];
    }

}

- (void)drawArea:(NSValue* __strong *)rect completion:(void (^ __nullable)(void))completion {
    if (!_isFullScreen) {
        *rect = [NSValue valueWithRect:[self fullScreenRect]];
    } else {
        [self drawScreenRect];
    }

    if (completion != NULL) {
        completion();
    }
}

Setter and getter:

- (void)setVideoRect:(NSValue*)videoRect {

    _videoRect = videoRect;

}

- (NSValue*)videoRect {

    return _videoRect;

}

Create video observer:

- (void)createVideoObserver {

    [[RACObserve(self, videoRect) skip:1] subscribeNext:^(id _) {

        [self start];

        [_presenter animateRecordButton:_isRecording];

    }];

}

I don’t understand why observer doesn’t work. How can I pass self.videoRect to the drawArea function?

nik3212
  • 392
  • 1
  • 6
  • 18
  • Maybe this is a duplicate of [What exactly does synthesize do](https://stackoverflow.com/questions/3266467/what-exactly-does-synthesize-do) – cwschmidt Aug 24 '17 at 20:26

1 Answers1

1

Your -drawArea:completion: method is taking a pointer to an NSValue, whereas self.videoRect is a property to an NSValue. In Swift, you can pass a property like this by reference, but in Objective-C, a property is really nothing more than a couple of methods, one of which sets an instance variable and one which returns it. So just passing the property into the method will not work. What you need to do is to read the property, pass a pointer to the resulting value, and then modify the property with the new value:

NSValue *videoRect = self.videoRect;
[self drawArea:&videoRect completion:^{
    ...

    self.videoRect = videoRect;
}];
Charles Srstka
  • 16,665
  • 3
  • 34
  • 60