Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
foss-2024-1-final
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
사랑 김
foss-2024-1-final
Commits
8536374b
Commit
8536374b
authored
1 year ago
by
사랑 김
Browse files
Options
Downloads
Patches
Plain Diff
Upload GCD.swift
parent
87499336
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Multi-threading_Practice/GCD.swift
+85
-0
85 additions, 0 deletions
Multi-threading_Practice/GCD.swift
with
85 additions
and
0 deletions
Multi-threading_Practice/GCD.swift
0 → 100644
+
85
−
0
View file @
8536374b
//
// 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
// }
//}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment