- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已阅读 documentation ,浏览了他们精彩的 Playground 示例,搜索了 S.O.,并达到了我的 google-fu 的范围。 ,但我无法终生思考如何使用 ReactiveSwift。
鉴于以下......
class SomeModel {
var mapType: MKMapType = .standard
var selectedAnnotation: MKAnnotation?
var annotations = [MKAnnotation]()
var enableRouteButton = false
// The rest of the implementation...
}
class SomeViewController: UIViewController {
let model: SomeModel
let mapView = MKMapView(frame: .zero) // It's position is set elsewhere
@IBOutlet var routeButton: UIBarButtonItem?
init(model: SomeModel) {
self.model = model
super.init(nibName: nil, bundle: nil)
}
// The rest of the implementation...
}
SomeViewController
使用
SomeModel
中的值,然后更新
SomeViewController
每当
SomeModel
中的值改变?
最佳答案
首先你要使用 MutableProperty
而不是模型中的普通类型。这样,您可以观察到它们的变化。
class Model {
let mapType = MutableProperty<MKMapType>(.standard)
let selectedAnnotation = MutableProperty<MKAnnotation?>(nil)
let annotations = MutableProperty<[MKAnnotation]>([])
let enableRouteButton = MutableProperty<Bool>(false)
}
class SomeViewController: UIViewController {
let viewModel: Model
let mapView = MKMapView(frame: .zero) // It's position is set elsewhere
@IBOutlet var routeButton: UIBarButtonItem!
init(viewModel: Model) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
routeButton.reactive.isEnabled <~ viewModel.enableRouteButton
viewModel.mapType.producer.startWithValues { [weak self] mapType in
// Process new map type
}
// Rest of bindings
}
// The rest of the implementation...
}
MutableProperty
两者都有,一个
.signal
以及
.signalProducer
.
MutableProperty
的当前值(例如对于初始设置),使用
.signalProducer
它立即发送带有当前值以及任何更改的事件。
.signal
这只会发送事件以供将来更改。
routeButton
完成的一样在示例中。
关于swift3 - ReactiveSwift 简单示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40836748/
我有一个简单的信号,在其中一个应用程序组件中,它返回一组项目: var itemsSignal: Signal 那些项目可能包含以表格 View 形式呈现在屏幕上的数据的更新。任务是将更新应用于屏幕上
我已阅读 documentation ,浏览了他们精彩的 Playground 示例,搜索了 S.O.,并达到了我的 google-fu 的范围。 ,但我无法终生思考如何使用 ReactiveSwif
我是 ReactiveSwift 的初学者。这是在我的 View 模型中获取代码: private let viewDidLoadProperty = MutableProperty(nil)
从 reactive swift 的文档中我可以理解Flattening。可以找到其中的示例 here .在 Flattening event streams 部分中,一切都得到了完美的讨论。 我对
我已经使用 ReactiveSwift 几个月了,但有一点我还没有完全理解:生命周期对象。 例如,假设我有一个将进行 API 调用的 SignalProducer,它包装在一个类中: class Se
我已多次阅读文档并需要澄清... 给定以下代码段: let signal: Signal //call this observer y signal.take(first: 1).observeVal
一般来说,ReactiveSwift 和 FRP 的新功能,试图构建一个小型计算器应用程序以尝试掌握它的窍门,但我一直在寻找响应式(Reactive)方法来做这样的事情。如果我有一个接受值的函数,我如
假设我有一个元素数组 [1, 2, 3] 和 5 秒的延迟。 我想发射数组的每个元素,在发射的当前元素和下一个元素之间有一个暂停。 例子: 输出: [00:00] -- 1 [00:05] -- 2
我正在训练自己使用 ReactiveSwift用于网络和一个很好的用例似乎是从 Google Places API for iOS 获取某个位置的照片. 流程如下: 从 Google 地点 ID 获取
当我用我想发送的字段做表单时,如果有我经常做的更改 let initialOrChangedName = Signal.merge( nameChanged.signal, self.vi
作为 this 的后续问题,收到 this fantastic answer ,并使用以下示例... class Model { let mapType = MutableProperty(.
人们如何转换我的代码: struct CarModel { var model: String? var make: String? var kilowatts: Int?
由于我是响应式(Reactive)编程的新手,所以我对在 ReactiveSwift 中链接 SignalProducers 有一些初学者的问题。我的目标是创建一个 SignalProducers 链
我是 ReactiveSwift 的初学者。我创建了天气应用程序,但我的请求不起作用。 func fetchCurrentWeather() -> SignalProducer { guard
我在我的项目中使用 ReactiveSwift,我想知道 PublishSubject 的等价物是什么? 例如在 RXSwift 中我们可以这样做: let disposeBag = DisposeB
我对使用 ReactiveSwift 和 ReactiveCocoa 相当陌生,我似乎遇到了有关初始化具有依赖项的属性的正确方法的障碍。 例如在下面的代码中,我尝试初始化一个属性,但我得到了预期的编译
现在我对 ReactiveSwift 很感兴趣,并尝试将其添加到项目的网络操作中。但是observeResult方法的action返回类型存在一些问题。 查看模型: final class TestV
您好,我是响应式 swift 的新手。在我的新项目中,我使用的是 ReactiveSwift。我通过使用 SafeSignal 变量观察值。我想在获取值之前中断信号。请帮我解决这个问题。 最佳答案 一
我使用 ReactiveSwift 有一段时间了,但突然遇到了一个奇怪的错误什么的。 我正在使用 MVVM 架构,并有一个简单的 View Controller 和一个 View 模型。 VM 具有类
我正在使用 ReactiveSwift 创建一个包含字典的结构。我想听字典的变化。 struct Model { let a: MutableProperty = MutablePropert
我是一名优秀的程序员,十分优秀!