私はリアクティブプログラミングを初めて使いました。私は一人では解決できない大きな問題があります。私はいくつかのビデオアセットを整然とした順序でアップロードする必要がありますが、 、私はPHAssetsの配列を持っていると私は各要素を通して反復して、ネットワーク経由で送信しようとしている ここに私のコードは、コメントで、これまでです:Loop with RxSwift
for item in items {
let fileName = item.media.localIdentifier
//Observable to generate local url to be used to save the compressed video
let compressedVideoOutputUrl = videoHelper.getDocumentsURL().appendingPathComponent(fileName)
//Observable to generate a thumbnail image for the video
let thumbnailObservable = videoHelper.getBase64Thumbnail(myItem: item)
//Observable to request the video from the iPhone library
let videoObservable = videoHelper.requestVideo(myItem: item)
//Compress the video and save it on the previously generated local url
.flatMap { videoHelper.compressVideo(inputURL: $0, outputURL: compressedVideoOutputUrl) }
//Generate the thumbnail and share the video to send over the network
let send = videoObservable.flatMap { _ in thumbnailObservable }
.flatMap { api.uploadSharedFiles(item, filename: fileName, base64String: $0) }
//subscribe the observable
send.subscribe(onNext: { data in
print("- Done chain sharing Video -")
},
onError: { error in
print("Error sharing Video-> \(error.localizedDescription)")
}).disposed(by: actionDisposeBag)
}
感謝を削除するリスクを回避するために、いくつかの説明を追加してください、私は質問、私はそれは、この場合に任意の使用されるであろう、concatMapについて読んされているがありますか? – Bruno
*トップレベルの.concatMap()*は、要素の順序が* items *の順序と同じであることを保証します。あなたがそれを必要とするかどうかを自分で確認してください。 –