Skip to content

Instantly share code, notes, and snippets.

View igorcferreira's full-sized avatar

Igor Castañeda Ferreira igorcferreira

View GitHub Profile
@igorcferreira
igorcferreira / FallbackJSONDecoder.swift
Created June 12, 2020 16:15
Demonstrate the usage of protocol for an easier Generic JSONDecoder with Fallback values
/// One of the motivations for this gist is a protocol that receives a Generic value and needs to return a value that may or may not be an optional.
/// Something like:
///
/// protocol Parser {
/// static func parse<T: Decodable>(data: Data) -> T?
/// }
///
/// This causes the issue of having to check the response type, even when you don't want to accept a nil value (ever)
/// let response: String? = parser.parse(data: Data())
/// if response == nil {
@igorcferreira
igorcferreira / ContentView.swift
Created January 15, 2024 20:14
Fetching view frame, including on List, using GeometryReader
struct ListCellView: View {
struct Selection: Equatable {
let label: String
let frame: CGRect
}
@State private var cellFrame: CGRect = .zero
let label: String
let action: (Selection) async -> Void