Skip to content

Instantly share code, notes, and snippets.

View paskowski's full-sized avatar
📱

Stanisław Paśkowski paskowski

📱
View GitHub Profile
// 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:
//
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
extension AsyncOperation {
override var isAsynchronous: Bool {
return true
}
override var isExecuting: Bool {
return state == .executing
}
import Foundation
class AsyncOperation: Operation {
public enum State: String {
case ready, executing, finished
fileprivate var keyPath: String {
return "is" + rawValue.capitalized
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let image = UIImage(named: "image-1.jpg")
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") }
import UIKit
class MonoImageOperation: Operation {
var inputImage: UIImage?
var outputImage: UIImage?
init(inputImage: UIImage) {
self.inputImage = inputImage
}
blurImageOperation.completionBlock = {
DispatchQueue.main.async {
self.bluredImageImageView.image = blurImageOperation.outputImage
self.bluringActivityIndicator.stopAnimating()
}
}
import UIKit
class BlurImageOperation: Operation {
var outputImage: UIImage?
override func main() {
guard let imageProvider = dependencies.first as? ImageProvider,
let providedImage = imageProvider.providedImage else { return }