In ReactiveCococa 2.5, RACMulticastConnection has a signal property, which is a RACSignal, while in its implementation, it has a ivar _signal, which is a RACSubject. I just wondered if the signal's backup ivar is the _signal, how to explain it?
ok, it seems that my question isn't clear, I put some demo code here, hope someone can answer it.
the header file:
@interface RACMulticastConnection : NSObject
@property (nonatomic, strong, readonly) RACSignal *signal;
...
@end
the impl file:
@interface RACMulticastConnection () {
RACSubject *_signal;
...
}
...
One more thing, there is no @synthesize code in its implementation and as you all known, RACSubject is a subclass of RACSignal.
Maybe...
@synthesize signalof any form then the property is auto-implementated (the standard approach) and the ivar_signalwill be used as the backing variable. If there was no ivar_signalthen one would be automatically created.That leaves two, primarily historical, options:
If there is an
@synthesize signalthen that will introduce an ivarsignalto use as the backing variable, and the declared ivar_signalwill not be associated in anyway to the property.Finally if there is an
@synthesize signal = _signalthen the ivar_signalwill be used as the backing variable.Addendum: After comment/question edit
Your edits to the question simply fix the above answer to the first bullet (the no
@synthesizecase).Maybe you are concerned over the property having the type
RACSignal *while the ivar has the typeRACSubject *?Remember the property is
readonlyso the only way to assign to it is using an assignment to_signalwithin the implementation, and the compiler will check that such an assignment has the typeRACSubject *(or a subtype).A client of the class reads the value using the property and is told the value is of type
RACSignal *, and it is asRACSubjectis a subclass ofRACSignalso everything is type correct.Using
RACSubject *for the ivar is a way to improve checking within the implementation - i.e. the property returns anRACSignal *but the implementation knows that it will always return the subclassRACSubjectso why not state that so the compiler will catch cases when it does not?To demonstrate the compiler is checking try changing the type of
_signal, say toNSArray, and you will get a compiler error stating that the type does not conform to the one required by the property.HTH