swift - 无法根据检查挂钩到另一个 RxSwift 流
问题描述
根据在网络请求之前添加的检查,无法连接到另一个 RxSwift 流。
我正在构建一个 UserProfile 对象,但我想确保 userProfile 对象已完全创建。我有一个正在创建 userProfile 对象的流,但现在我有一个检查。我想挂钩到前一个流,以便在完整的 UserProfile 上我可以执行网络请求。我不确定如何连接到上一个流。updateUserProfile($0) 是我传递 UserProfile 对象以发出网络请求的地方,但我想确保我停在那里。
let userInfoResponse = latestLocallySavedUserProfileDictionary
.map { (dictionary: [String: String?]) in
return UserProfile(
firstName: dictionary["firstName"] ?? "",
lastName: dictionary["lastName"] ?? "",
phone: dictionary["phone"] ?? "",
company: dictionary["company"] ?? "",
organizationType: dictionary["organizationType"] ?? "",
jobFunction: dictionary["jobFunction"] ?? "",
addressLine1: dictionary["addressLine1"] ?? "",
addressLine2: dictionary["addressLine2"] ?? "",
city: dictionary["city"] ?? "",
state: dictionary["state"] ?? nil,
zipCode: dictionary["zipCode"] ?? "",
country: dictionary["country"] ?? "",
languageCode: dictionary["languageCode"] ?? "",
merrillDisclaimerAccepted: false, // ignore for now
merrillDisclaimerAcceptedDate: "" // ignore for now
)
}
.flatMapLatest { updateUserProfile($0) }
.share()
isUserProfileDictionaryComplete = Observable.merge([
initialUserProfileCall,
userInfoResponse
.map{$0.createDictionary()},
userProfileLocal
])
.asObservable()
.map{(profileDictionary) -> Bool in
return profileDictionary.values.contains(nil) || profileDictionary.values.contains("")
}
.ignore(true)
解决方案
我不太明白您要做什么,但总的来说,您需要找出所有应该提示网络请求的事件,并将它们放在 flatMapLatest 之前的流中。
UserProfile
如果您尝试从latestLocallySavedUserProfileDictionary
,构建 a initialUserProfileCall
,userProfileLocal
那么您可能希望在合并后进行扫描以收集每个字典中的所有位。
推荐阅读
- android - 谷歌地图获取特定位置的所有瓷砖位置
- sql - 如何为每个公司的每种产品类型获得最便宜的产品?
- bash - 回声输出与预期的格式化输出不同
- haskell - 如何在 Haskell IO 中用空格 n 分隔用户输入的字符串
- tensorflow - TensorFlow 服务:无法进行 base64 解码
- android - 将数组从android传递到phpmysql数据库
- jenkins - Jenkins - SVN 中存在更改,但 Jenkins 没有显示任何更改,但构建正在运行
- google-analytics - 谷歌分析过滤垃圾邮件包含一个按广告系列来源的词
- unity3d - Unity - 如何在运行时更改播放器精灵表?
- javascript - 在 Promise.all 期间创建随机数据