我如何在另一个函数中使用 retailId(来自 flatMapLatest)

how i can use retailId(from flatMapLatest) in another func

视图模型:

        searchButtonInDidTapSubject.withLatestFrom(retailIdSubject.map { text in return text}).flatMapLatest { [unowned self] retailId in
        return service.searchRetailPayCashBack(retailId: retailId, createdAt: self.createdDates, sig: self.sig).materialize();
        }.subscribe(onNext: { [weak self] event in
            switch (event) {
            case .next(_):
                self?.checkResultSubject.onNext(true)
                break;
            case .error(let error):
                self?.errorSubject.onNext(error as! ErrorResponse);
                break;
            default:
                break;
            }
        }).disposed(by: disposeBag);

// 这里我需要转换 retailId , currentTime 和 accessToken 之后我发送请求 api

 private var sig: String{
get {
    let accessToken = self.keychain.get(Constants.accessToken)
    // ???
    let newAccessToken = String((accessToken?.substring(with: 11..<21))!)
    let retailid = ???
    let newSig = "\(newAccessToken)\(self.createdDates)\(retailid)"
    let md5Base64 = newSig.base64Encoded()
    let md5Data = self.MD5(md5Base64!)
    return String(md5Data!)

}
}

retailId 需要等于 retailid

不确定您想要实现什么,但听起来 sig 应该在您每次点击按钮时生成,因为 retailId 可能不同。

searchButtonInDidTapSubject
    .withLatestFrom(retailIdSubject.map { text in return text })
    .flatMapLatest { [unowned self] retailId in
        return service
            .searchRetailPayCashBack(
                retailId: retailId,
                createdAt: self.createdDates,
                sig: self.sig(withRetailId: retailId, createdDate: self.createdDates)
            )
            .materialize()
    }
    .subscribe(onNext: { [weak self] event in
        switch (event) {
        case .next(_):
            self?.checkResultSubject.onNext(true)
            break;
        case .error(let error):
            self?.errorSubject.onNext(error as! ErrorResponse);
            break;
        default:
            break;
        }
    })
    .disposed(by: disposeBag)

func sig(withRetailId retailId: String, createdDate: String) -> String {
    let accessToken = self.keychain.get(Constants.accessToken)
    // ???
    let newAccessToken = String((accessToken?.substring(with: 11..<21))!)
    let newSig = "\(newAccessToken)\(createdDate)\(retailId)"
    let md5Base64 = newSig.base64Encoded()
    let md5Data = self.MD5(md5Base64!)
    return String(md5Data!)
}