Swift Synchronous API calls
up vote
-3
down vote
favorite
I have to make three API calls to server one after another(synchronous),second API has to be called only if the first one is success. If first API fails then I have to to stop the flow and show another view controller with retry and cancel. What should I use and How should I do it?
objective-c swift grand-central-dispatch
New contributor
add a comment |
up vote
-3
down vote
favorite
I have to make three API calls to server one after another(synchronous),second API has to be called only if the first one is success. If first API fails then I have to to stop the flow and show another view controller with retry and cancel. What should I use and How should I do it?
objective-c swift grand-central-dispatch
New contributor
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
3
There are more than one solutions to your problem. Here are some keywords that you should be looking for:NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)
– Alladinian
yesterday
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I have to make three API calls to server one after another(synchronous),second API has to be called only if the first one is success. If first API fails then I have to to stop the flow and show another view controller with retry and cancel. What should I use and How should I do it?
objective-c swift grand-central-dispatch
New contributor
I have to make three API calls to server one after another(synchronous),second API has to be called only if the first one is success. If first API fails then I have to to stop the flow and show another view controller with retry and cancel. What should I use and How should I do it?
objective-c swift grand-central-dispatch
objective-c swift grand-central-dispatch
New contributor
New contributor
New contributor
asked yesterday
Revathi Bhavanam
11
11
New contributor
New contributor
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
3
There are more than one solutions to your problem. Here are some keywords that you should be looking for:NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)
– Alladinian
yesterday
add a comment |
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
3
There are more than one solutions to your problem. Here are some keywords that you should be looking for:NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)
– Alladinian
yesterday
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
3
3
There are more than one solutions to your problem. Here are some keywords that you should be looking for:
NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)– Alladinian
yesterday
There are more than one solutions to your problem. Here are some keywords that you should be looking for:
NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)– Alladinian
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Using TRVSURLSessionOperation would help you, here is how to do it:
let queue = OperationQueue()
let session = URLSession(configuration: URLSessionConfiguration.default)
let firstOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "first url")!)) { (data, response, error) in
// Your completion logic
}
let secondOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "second url")!)) { (data, response, error) in
// Your completion logic
}
secondOperation?.addDependency(firstOperation!)
queue.addOperations([firstOperation!, secondOperation!], waitUntilFinished: false)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Using TRVSURLSessionOperation would help you, here is how to do it:
let queue = OperationQueue()
let session = URLSession(configuration: URLSessionConfiguration.default)
let firstOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "first url")!)) { (data, response, error) in
// Your completion logic
}
let secondOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "second url")!)) { (data, response, error) in
// Your completion logic
}
secondOperation?.addDependency(firstOperation!)
queue.addOperations([firstOperation!, secondOperation!], waitUntilFinished: false)
add a comment |
up vote
0
down vote
Using TRVSURLSessionOperation would help you, here is how to do it:
let queue = OperationQueue()
let session = URLSession(configuration: URLSessionConfiguration.default)
let firstOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "first url")!)) { (data, response, error) in
// Your completion logic
}
let secondOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "second url")!)) { (data, response, error) in
// Your completion logic
}
secondOperation?.addDependency(firstOperation!)
queue.addOperations([firstOperation!, secondOperation!], waitUntilFinished: false)
add a comment |
up vote
0
down vote
up vote
0
down vote
Using TRVSURLSessionOperation would help you, here is how to do it:
let queue = OperationQueue()
let session = URLSession(configuration: URLSessionConfiguration.default)
let firstOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "first url")!)) { (data, response, error) in
// Your completion logic
}
let secondOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "second url")!)) { (data, response, error) in
// Your completion logic
}
secondOperation?.addDependency(firstOperation!)
queue.addOperations([firstOperation!, secondOperation!], waitUntilFinished: false)
Using TRVSURLSessionOperation would help you, here is how to do it:
let queue = OperationQueue()
let session = URLSession(configuration: URLSessionConfiguration.default)
let firstOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "first url")!)) { (data, response, error) in
// Your completion logic
}
let secondOperation = TRVSURLSessionOperation(session: session, request: URLRequest(url: URL(string: "second url")!)) { (data, response, error) in
// Your completion logic
}
secondOperation?.addDependency(firstOperation!)
queue.addOperations([firstOperation!, secondOperation!], waitUntilFinished: false)
edited yesterday
answered yesterday
MuhammadBassio
1,364812
1,364812
add a comment |
add a comment |
Revathi Bhavanam is a new contributor. Be nice, and check out our Code of Conduct.
Revathi Bhavanam is a new contributor. Be nice, and check out our Code of Conduct.
Revathi Bhavanam is a new contributor. Be nice, and check out our Code of Conduct.
Revathi Bhavanam is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372229%2fswift-synchronous-api-calls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use Operation Queue and manage the dependency using OperationQueue
– HPM
yesterday
3
There are more than one solutions to your problem. Here are some keywords that you should be looking for:
NSOperation
, GCD, futures & promises, async/await pattern. The way that Apple handles this is by operations that depend on other operations. Use of Promises is quite popular for these tasks and finally async/await maybe the cleanest (cognitive load wise) approach to promises (and what I would suggest you to check first)– Alladinian
yesterday