Skip to content
Snippets Groups Projects
Commit 8536374b authored by 사랑 김's avatar 사랑 김 :military_medal:
Browse files

Upload GCD.swift

parent 87499336
No related branches found
No related tags found
No related merge requests found
//
// GCD.swift
// FOSS_PR
//
// Created by 김사랑 on 2024/06/23.
//
//import UIKit
//
//let catAPIURL = "https://api.thecatapi.com/v1/images/search?limit=3"
//
//extension ViewController {
//
// func downloadImagesUsingGCD() {
// guard let url = URL(string: catAPIURL) else { return }
//
// DispatchQueue.global().async {
// do {
// let data = try Data(contentsOf: url)
// if let jsonArray = try JSONSerialization.jsonObject(with: data, options:[]) as? [[String: Any]] {
// var downloadedImages: [UIImage] = []
// let dispatchGroup = DispatchGroup()
// for json in jsonArray {
// if let imagesUrlString = json["url"] as? String,
// let imageUrl = URL(string: imagesUrlString) {
// dispatchGroup.enter()
//
// DispatchQueue.global().async {
// if let imageData = try? Data(contentsOf: imageUrl),
// let image = UIImage(data: imageData) {
// downloadedImages.append(image)
// }
// dispatchGroup.leave()
// }
// }
// }
//
// dispatchGroup.notify(queue: .main) {
// self.originalImgaes = downloadedImages
// self.images = downloadedImages
// self.collectionView.reloadData()
// }
// }
// } catch {
// DispatchQueue.main.async {
// let alert = UIAlertController(title: "Error", message: "Failed to load images", preferredStyle: .alert)
// alert.addAction(UIAlertAction(title: "OK", style: .default))
// self.present(alert, animated: true)
// }
// }
// }
// }
//
// func applyFilterUsingGCD() {
// DispatchQueue.global().async {
// var filteredImages: [UIImage] = []
// for image in self.originalImgaes {
// let filteredImage = self.applyFilter(to: image)
// filteredImages.append(filteredImage)
// }
// DispatchQueue.main.async {
// self.images = filteredImages
// self.collectionView.reloadData()
// }
// }
// }
//
// func resetImagesUsingGCD() {
// DispatchQueue.main.async {
// self.images = self.originalImgaes
// self.collectionView.reloadData()
// }
// }
//
// func applyFilter(to image: UIImage) -> UIImage {
// let context = CIContext()
// let filter = CIFilter(name: "CIPhotoEffectNoir")
// filter?.setValue(CIImage(image: image), forKey: kCIInputImageKey)
// if let outputImage = filter?.outputImage,
// let cgImage = context.createCGImage(outputImage, from: outputImage.extent) {
// return UIImage(cgImage: cgImage)
// }
// return image
// }
//}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment