This file contains hidden or 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 ImageCache { | |
static let shared = ImageCache() | |
fileprivate let cache = NSCache<NSString, UIImage>() | |
func set(key: String, image: UIImage) { | |
DispatchQueue.main.sync { | |
cache.setObject(image, forKey: key as NSString) | |
} |
This file contains hidden or 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 | |
extension UIImageView { | |
func downloadImageAsync(urlString: String, defaultImage: UIImage, success: @escaping ()->(), failure: @escaping ()->()) { | |
if let image = ImageCache.shared.get(key: urlString) { | |
self.image = image | |
} else { | |
// We can set default image here | |
self.image = defaultImage | |
DispatchQueue.global().async (execute: { |
This file contains hidden or 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
DispatchQueue.main.async { | |
print("This is GCD talking baby.") | |
print("I have a lot more to offer!") | |
} |
This file contains hidden or 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
// | |
// DebugBorder.swift | |
// Trial | |
// | |
// Created by Gungor Basa on 11/30/23. | |
// | |
import SwiftUI | |
extension View { |