Objective c 将self.property传递给函数
我对获取属性有问题。当我将direct传递给drawArea函数时,什么都没有发生。但如果我改变了自我,那就完美了 我的代码:Objective c 将self.property传递给函数,objective-c,reactive-cocoa,Objective C,Reactive Cocoa,我对获取属性有问题。当我将direct传递给drawArea函数时,什么都没有发生。但如果我改变了自我,那就完美了 我的代码: @property (nonatomic, assign) BOOL isRecording; @property (nonatomic) NSValue* videoRect; @implementation Interactor @synthesize videoRect = _videoRect; - (id)init { _isRecording =
@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();
}
}
塞特和盖特:
- (void)setVideoRect:(NSValue*)videoRect {
_videoRect = videoRect;
}
- (NSValue*)videoRect {
return _videoRect;
}
创建视频观察者:
- (void)createVideoObserver {
[[RACObserve(self, videoRect) skip:1] subscribeNext:^(id _) {
[self start];
[_presenter animateRecordButton:_isRecording];
}];
}
我不明白为什么观察家不工作。如何将self.videoRect传递给drawArea函数 您的
-drawArea:completion:
方法将指针指向NSValue
,而self.videoRect
是NSValue
的属性。在Swift中,可以通过引用传递这样的属性,但在Objective-C中,属性实际上只不过是两个方法,其中一个设置实例变量,另一个返回实例变量。因此,仅将属性传递到方法将不起作用。您需要做的是读取属性,传递指向结果值的指针,然后使用新值修改属性:
NSValue *videoRect = self.videoRect;
[self drawArea:&videoRect completion:^{
...
self.videoRect = videoRect;
}];
也许这是一个复制品