Skip to content

Instantly share code, notes, and snippets.

View imthath-m's full-sized avatar
💭
developmentMode

Mohammed Imthathullah imthath-m

💭
developmentMode
View GitHub Profile
@imthath-m
imthath-m / ComparingCodables.swift
Created February 25, 2020 14:09
Provide default implemenation for Equatable classes conforming to Codable
import Foundation
public extension Equatable where Self: Codable {
static func ==(lhs: Self, rhs: Self) -> Bool {
lhs.jsonData == rhs.jsonData
}
}
public extension Person: Equatable { }
@imthath-m
imthath-m / Imitable.swift
Last active February 25, 2020 13:46
Conform to this protocol to easily deep copy reference types in Swift.
import Foundation
public protocol Imitable: Codable {
var copy: Self? { get }
}
extension Imitable {
public var copy: Self? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return try? JSONDecoder().decode(Self.self, from: data)
@imthath-m
imthath-m / SwiftUIRendering.swift
Last active January 21, 2023 14:04
Sample View to demonstrate how often SwiftUI redraws its views.
import SwiftUI
struct SampleView: View {
var texts = ["SwiftUI", "A new declarative UI framework", "Let us try to understand how SwiftUI renders its views"]
@State var selected = 0
@State var textFieldValue = ""
@State var isSwitchOn = false