objective c - Transform an array of value with async function and Reactive-Cocoa -


i have array of string , want modify calling asynchronous function on each value.

i tried it's creating racsequence of racsignal , not array of modified string

func modifyvalueasynchronously(inputvalue: string, completion: (string -> void)) -> racsignal  {     return racsignal.createsignal() { subscriber in         doaservercall(inputvalue) { outputvalue in             subscriber.sendnext(outputvalue)         }     } }  let value: nsarray = ["a", "b"]  let result = value.rac_sequence.map({ value in     return self.dorequest(value as! string) }) 

as said, want perform asynchronous function on each of string values in array. because of fact async, final result arrive asynchronous. after getting racsequence of racsignal, want wait until each signal provides value , gather array.

let transformation = { (input: string) -> racsignal in         return racsignal.createsignal { subscriber in             subscriber.sendnext(input + "a")             return nil         }     }      let array: nsarray = ["a", "b", "c", "d"]      let sequence = array.rac_sequence.map({ (element) in         return transformation(element as! string)     })     racsignal.combinelatest(sequence).subscribenext { (element) in         let array = (element as! ractuple).allobjects()         print("elements array \(array) \n")     } 

lets take example. transformation closure asynchronously add 'a' letter each string. after creating sequence, add combinelatest operator give me result each element sequence provides me it's result. results, ractuple inside subscribenext method , can make array out of it.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -