0

I have the following code in a viewmodel:

@weakify(self);
[RACAbleWithStart(self.visitStartDate) subscribeNext:^(NSDate *visitStartDate) {
    @strongify(self);
    self.visit.startDate = visitStartDate;
}];
[RACAbleWithStart(self.visitEndDate) subscribeNext:^(NSDate *visitEndDate) {
    @strongify(self);
    self.visit.endDate = visitEndDate;
}];
[RACAbleWithStart(self.visitFocus) subscribeNext:^(NSString *focus) {
    @strongify(self);
    self.visit.actionPlan.focus = focus;
}];
[RACAbleWithStart(self.allDayVisit) subscribeNext: ^(NSNumber *allDayVisit) {
    @strongify(self);
    self.visit.allDay = allDayVisit;
}];

It is basically binding properties onto a private property. Is this totally the wrong way of going about this or is there a tidier way of writing the above code?

4

1 回答 1

2

尝试这个:

RAC(self.visit, startDate) = RACAbleWithStart(self.visitStartDate);

从 RAC 宏的标题注释中:

// Lets you assign a keypath / property to a signal. The value of the keypath or
// property is then kept up-to-date with the latest value from the signal.
//
// If given just one argument, it's assumed to be a keypath or property on self.
// If given two, the first argument is the object to which the keypath is
// relative and the second is the keypath.
//
// Examples:
//
//  RAC(self.blah) = someSignal;
//  RAC(otherObject, blah) = someSignal;
于 2013-06-14T20:33:05.797 回答