- iOS 9.0+
INLAsyncOperation is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'INLAsyncOperation'
- run
pod install
in your repository import INLAsyncOperation
- Subclass
AsynchronousOperation
- Override
main()
- Put your task implementation in
main()
of your custom class
See the example INLAsyncOperationExample
as a reference.
struct OperationDispatcher {
private let queue = OperationQueue()
func dispatch(_ operation: Operation) {
queue.addOperation(operation)
}
}
final class SampleOperation: AsynchronousOperation {
typealias CompletionClosure = (_ emojis: [String]) -> Void
private let completion: CompletionClosure
init(completion: @escaping CompletionClosure) {
self.completion = completion
}
override func main() {
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
let array = [String](repeating: "🎉", count: 100)
self.completion(array)
}
}
}
radimhalfar, radim.halfar@inloop.eu
INLAsyncOperation is available under the MIT license. See the LICENSE file for more info.