This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class BlurImageOperation: Operation { | |
var outputImage: UIImage? | |
override func main() { | |
guard let imageProvider = dependencies.first as? ImageProvider, | |
let providedImage = imageProvider.providedImage else { return } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blurImageOperation.completionBlock = { | |
DispatchQueue.main.async { | |
self.bluredImageImageView.image = blurImageOperation.outputImage | |
self.bluringActivityIndicator.stopAnimating() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class MonoImageOperation: Operation { | |
var inputImage: UIImage? | |
var outputImage: UIImage? | |
init(inputImage: UIImage) { | |
self.inputImage = inputImage | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let printerOperation = BlockOperation() | |
printerOperation.addExecutionBlock { print("I") } | |
printerOperation.addExecutionBlock { print("am") } | |
printerOperation.addExecutionBlock { print("printing") } | |
printerOperation.addExecutionBlock { print("block") } | |
printerOperation.addExecutionBlock { print("operation") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var imageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let image = UIImage(named: "image-1.jpg") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class AsyncOperation: Operation { | |
public enum State: String { | |
case ready, executing, finished | |
fileprivate var keyPath: String { | |
return "is" + rawValue.capitalized | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension AsyncOperation { | |
override var isAsynchronous: Bool { | |
return true | |
} | |
override var isExecuting: Bool { | |
return state == .executing | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class AsyncImageDownloadOperation: AsyncOperation { | |
var downloadedImage: UIImage? | |
override func main() { | |
let defaultSession = URLSession(configuration: .default) | |
guard let imgUrl = URL(string: "https://unsplash.com/photos/M9O6GRrEEDY/download?force=true") else { return } | |
let dataTask = defaultSession.dataTask(with: imgUrl) { (data, response, error) in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2024 Gwendal Roué | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the | |
// "Software"), to deal in the Software without restriction, including | |
// without limitation the rights to use, copy, modify, merge, publish, | |
// distribute, sublicense, and/or sell copies of the Software, and to permit | |
// persons to whom the Software is furnished to do so, subject to the | |
// following conditions: | |
// |