I am building a Swift-based iOS application that uses PromiseKit to handle promises (although I am open to switching if this makes it easier to solve my problem). There is a section of code designed to handle file rewriting issues.
I have some code that looks something like this:
let fileList = [list, of, files, could, be, any, length, ...]
for file in fileList {
if(fileAlreadyExists) {
let overwrite = Promise<Bool> { fulfill, reject in
let alert = UIAlertController(message: "Overwrite the file?")
alert.addAction(UIAlertAction(title: "Yes", handler: { action in
fulfill(true)
}
alert.addAction(UIAlertAction(title: "No", handler: { action in
fulfill(false)
}
} else {
fulfill(true)
}
}
overwrite.then { result -> Promise<Void> in
Promise<Void> { fulfill, reject in
if(result) {
} else {
}
}
}
; "" , , , , UIAlertController , . , promises , , "" "" ( "" " " ), for . , , .
promises, ? , - .
: . , , Swift ( iOS), . , , , .