Skip to content

Instantly share code, notes, and snippets.

View gungorbasa's full-sized avatar
😄
As always, building awesome things with awesome people 😉

Güngör gungorbasa

😄
As always, building awesome things with awesome people 😉
View GitHub Profile
@gungorbasa
gungorbasa / DebugBorder.swift
Created November 30, 2023 11:46
Create a debug border extension for SwiftUI code to understand when a view is redrawn.
//
// DebugBorder.swift
// Trial
//
// Created by Gungor Basa on 11/30/23.
//
import SwiftUI
extension View {
DispatchQueue.main.async {
print("This is GCD talking baby.")
print("I have a lot more to offer!")
}
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: {
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)
}