简体   繁体   English

Rxswift如何调用1个或多个函数以返回另一个函数

[英]Rxswift how to call 1 or more functions in return of the other function

I have used RxSwift to call other function in the return of the first function.我已经使用 RxSwift 在第一个函数的返回中调用其他函数。 For that I have tried this code:为此,我尝试了以下代码:

func startSyncNow(_ call: CAPPluginCall,lastSyncTime: String) -> Observable<String> {
         return   createOrAlterTable(call)

            .flatMapLatest(){ query -> Observable<String> in
                let formschema = self.formSchemaToSQLite(call, lastSyncTime: lastSyncTime)
               return formschema
        }.flatMapLatest(){ query -> Observable<String> in
            let menuTable = self.menuTableRecord(call, lastSyncTime: lastSyncTime)
               return menuTable
        }
        .map { query -> String in
            return "Success"
       }
    }
    
    func  createOrAlterTable(_ call: CAPPluginCall) -> Observable<[[String:Any]]>{
    
     return Observable.just("Sucess")
    }
    
    func formSchemaToSQLite(_ call: CAPPluginCall,lastSyncTime : String) -> Observable<String> {
        return Observable.just("Sucess")
    }
    
    
    func menuTableRecord(_ call: CAPPluginCall,lastSyncTime:String) -> Observable<String>{
        return Observable.just("Sucess")
    }

When I am debugging this code, I am not able to hit debug point on either formSchemaToSQLite or recordsTOSqlite.当我调试这段代码时,我无法在 formSchemaToSQLite 或 recordsTOSqlite 上找到调试点。 Please guide me what I am missing请指导我我所缺少的

The following both compiles and when you call the example() function, all the functions are called:以下都编译,当您调用example()函数时,所有函数都被调用:

struct CAPPluginCall { }

func example() {
    _ = startSyncNow(CAPPluginCall(), lastSyncTime: "before")
        .subscribe(onNext: { result in
            print(result)
        })
}

func startSyncNow(_ call: CAPPluginCall, lastSyncTime: String) -> Observable<String> {
    return createOrAlterTable(call)
        .flatMapLatest { query -> Observable<String> in
            let formschema = formSchemaToSQLite(call, lastSyncTime: lastSyncTime)
            return formschema
        }
        .flatMapLatest { query -> Observable<String> in
            let menuTable = menuTableRecord(call, lastSyncTime: lastSyncTime)
            return menuTable
        }
        .map { query -> String in
            return "Success"
        }
}

func createOrAlterTable(_ call: CAPPluginCall) -> Observable<[[String:Any]]>{
    return Observable.just([[:]])
}

func formSchemaToSQLite(_ call: CAPPluginCall,lastSyncTime : String) -> Observable<String> {
    return Observable.just("Sucess")
}


func menuTableRecord(_ call: CAPPluginCall,lastSyncTime:String) -> Observable<String>{
    return Observable.just("Sucess")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM