https://github.com/kiarashvosough1999/statefulloperation
https://github.com/kiarashvosough1999/statefulloperation
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kiarashvosough1999/statefulloperation
- Owner: kiarashvosough1999
- License: mit
- Created: 2022-02-15T15:35:49.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-04T18:46:58.000Z (about 3 years ago)
- Last Synced: 2025-01-29T13:45:40.738Z (9 months ago)
- Language: Swift
- Size: 230 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StateFullOpertaion


[](https://twitter.com/vosough_k)
[](https://www.linkedin.com/in/kiarashvosough/)Unleash the power of Operation with StateFullOpertaion
- [Requirements](#requirements)
- [Installation](#installation)
- [SampleProjects](#sample)
- [Usage](#usage)
- [Contributors](#contributors)
- [License](#license)## Requirements
| Platform | Minimum Swift Version | Installation | Status |
| --- | --- | --- | --- |
| iOS 9.0+ | 5.3 | [CocoaPods](#cocoapods) | Tested |## Installation
### CocoaPods
[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate StateFullOpertaion into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'StateFullOpertaion'
```## Sample
I have provided one sample project in the repository. To use it clone the repo, Source files for these are in the `Example` directory in project navigator. Have fun!
## Usage
### SafeOperation
SafeOperation is a convinient way of using operation.
It offers new features which the operation itself does not support or could be so tricky to use.> Subclasses must not override any method of the base Opertaion Class or call them
, instead they can override the provided method on protocol `OperationLifeCycleProvider` to take control of what should be done.
> `enqueueSelf` can be use to add operation to a Queue, just make sure you provide operation a queue within its initializer.#### Subclassing
```swift
class MyOperation: SafeOperation {
override func shouldStartRunnable() throws {
try super.shouldStartRunnable()
/// do some pre-requireties before the runnable start
}
override func runnable() throws {
/// impelement your task here
/// call `cancelRunnable()` whenever the task finish
}
override func finishRunnable() throws {
try finishRunnable()
/// make sure you call `finishRunnable()`
}
override func didFinishRunnable() {
// this method will be called sync-ly after runnable retured
// if `runnable()` overrided, after it is finished,
// `super.runnable()` can be called to run `didFinishRunnable()`
// this method will be also called after calling `finishRunnable()`
// do whatever after the runnable finished
}
override func cancelRunnable() throws {
try super.cancelRunnable()
/// make sure you call `super.cancelRunnable()` in order to change operation flag
}
override func didCancelRunnable() {
/// after operation canceled and before the operation is poped from queue this method will be called
}
}
```#### Closure
you may want to add operation with out all feature it provide with subclassing, using new method on OperationQueue can become handy.
```swift
let queue = OperationQueue()
queue.addOperation(identifier: .unique(), queuePriority: .normal, qualityOfService: .background) { completed in
// your code
// after you've done the completed block should be called to dequeue operation from queue
ompleted()
} onCompleted: {
// will be call just right before the dequeing operation from queue
} onCanceled: {
// called when `cancelRunnable()` is called
} onFinished: {
// called when `completed()` is called inside operation block
} onExecuting: {
// called when opertion is enqued and started
}```
## Contributors
Feel free to share your ideas or any other problems. Pull requests are welcomed.
## License
CocoAttributedStringBuilder is released under an MIT license. See [LICENSE](https://github.com/kiarashvosough1999/StateFullOpertaion/blob/master/LICENSE) for more information.