ios - 如何在具有多个子选择的 ReSwift 中定义 `newState`?

标签 ios swift redux reswift

我们使用了 ReSwift在一些 iOS 项目中,并且一直很喜欢它。在 4.0 ,他们添加了子选择部分状态和 skipRepeats 的功能,可以手动或使用 Equatable 的存储。子选择商店很简单:

store.subscribe(subscriber) {
  $0.select {
    $0.testValue
  }
}

然后你定义newState:

func newState(state:TestValue) {
   // handle new state
}

当通过元组传递多个参数时,我对如何定义 newState 有点困惑:

store.subscribe(subscriber) {
  $0.select {
    ($0.testValue, $0.otherState?.name)
  }
}

我正在传递元组,但看到 Type 'MainViewController' does not conform to protocol 'StoreSubscriber'Type of expression is ambiguous without more context 错误:

func newState((testState: TestValue, name: String)) {
    // handle new state
}

我在这里做错了什么?

最佳答案

当然这是我的一个简单错误。我需要将传递的元组命名为 state

func newState(state: (testState: TestValue, name: String)) {
    // handle new state
}

关于ios - 如何在具有多个子选择的 ReSwift 中定义 `newState`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45014853/

相关文章:

android - Android 中所有应用的设备 token 是否相同?

javascript - 使用 Javascript 在 UIWebView 中跳转搜索结果

ios - 无法将类型 '__NSDictionaryM' 的值转换为 'NSArray"

swift - Swift 中展开的可选数组的相等性

reactjs - Ant 设计: get Id from datepicker in onChange

ios - 如何提高登录认证的速度?

json - 使用名为 self 的元素解码 JSON

ios - AppDelegate : call function only if theres a new notification, 怎么办?

javascript - 创建一个纯函数来合并对象

javascript - 为复杂的关系域模型构建 Redux 状态