gpt4 book ai didi

ios - 重构 ReactiveCocoa

转载 作者:行者123 更新时间:2023-11-28 22:32:04 26 4
gpt4 key购买 nike

我在 View 模型中有以下代码:

@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;
}];

它基本上是将属性绑定(bind)到私有(private)属性上。这是完全错误的处理方式还是有更简洁的方式来编写上述代码?

最佳答案

试试这个:

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;

关于ios - 重构 ReactiveCocoa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17116273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com