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
// This is an experiment for moving a view between different stacks and having SwiftUI animate it properly. | |
// By "drawing" all of the cards in one place and moving their geometry, it preserves the card view's | |
// identifity from SwiftUI's POV. This means when things change, SwiftUI can understand how they changed | |
// and animate it properly. Is there a better way to do this? | |
class Card : Identifiable, ObservableObject, Equatable { | |
@Published var name: String | |
@Published var tagged = false | |
init(_ name: String) { |
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
// This gist demonstrates how you can implement versioning for a Codable struct to support loading | |
// old serialized data after changing the structure. Notable features of this solution: | |
// | |
// * No need to make new properties optional, or to perform post-processing on the struct after | |
// loading in ordeer to populate missing values | |
// * No need to change the call site - from the outside this struct behaves just the same | |
// as if we had implemented codable directly in the normal way. | |
// * Versioning can be applied individually to parents or leaves in a larger tree of | |
// structs without affecting the other elements | |
// * This approach will work even if the original struct was not designed with versioning in mind |
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
<?xml version="1.0" encoding="UTF-8" ?> | |
<!DOCTYPE CDXML SYSTEM "http://www.cambridgesoft.com/xml/cdxml.dtd" > | |
<CDXML | |
CreationProgram="ChemDraw 14.0.0.118" | |
Name="Human_Body.cdx" | |
BoundingBox="5.57 2.92 538.65 658.35" | |
WindowPosition="0 0" | |
WindowSize="0 0" | |
FractionalWidths="yes" | |
InterpretChemically="yes" |
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
/// After reading an article from Antoine v.d. SwiftLee @twannl about conditional view modifier, I had an idea to improve my code I write for specific OS. | |
/// https://www.avanderlee.com/swiftui/conditional-view-modifier | |
extension Bool { | |
static var iOS: Bool { | |
#if os(iOS) | |
return true | |
#else | |
return false | |
#endif |
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
// | |
// Color+Codable.swift | |
// FirestoreCodableSamples | |
// | |
// Created by Peter Friese on 18.03.21. | |
// | |
import SwiftUI | |
// Inspired by https://cocoacasts.com/from-hex-to-uicolor-and-back-in-swift |
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
extension Collection { | |
func parallelMap<T>( | |
parallelism requestedParallelism: Int? = nil, | |
_ transform: @escaping (Element) async throws -> T | |
) async throws -> [T] { | |
let defaultParallelism = 2 | |
let parallelism = requestedParallelism ?? defaultParallelism | |
let n = self.count | |
if n == 0 { |
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 Combine | |
import ObjectiveC.runtime | |
extension NSObject { | |
private enum AssociatedKeys { | |
static var CancellablesKey = "CancellablesKey" | |
} | |
/// A set that can be used to dispose of Combine cancellables. | |
public var cancellables: Set<AnyCancellable> { |
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 Foundation | |
public extension DispatchQueue { | |
private struct _once_Domain: Hashable { | |
/// The unique identifier for the class instance as domain. | |
var identifier: ObjectIdentifier | |
/// A weak reference to the class instance as domain. | |
weak var lifetimeObject: NSObject? |
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
struct User: Equatable { | |
var firstName: String | |
var lastName: String | |
} | |
@main | |
struct MyApp: App { | |
@State var value = User(firstName: "", lastName: "") | |
@State var showEdit = false |