简体   繁体   中英

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. 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. Please guide me what I am missing

The following both compiles and when you call the example() function, all the functions are called:

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")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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