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 | |
| struct SomeObject: Codable { | |
| let name: String | |
| } | |
| struct OtherObject: Codable { | |
| let number: Int | |
| } |
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
| enum Color { | |
| case red | |
| } | |
| struct carsA { | |
| let ofColor: Color | |
| } | |
| let carsA = carsA(ofColor: .red) // error: Circular reference |
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 SwiftUI | |
| protocol Selectable: Identifiable { | |
| associatedtype Label : View | |
| var isSelected: Bool { get set } | |
| var label: Label { get } | |
| } | |
| struct Multiselect<T: Selectable>: View { | |
| @Binding var items: [T] |
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 SwiftUI | |
| struct ContentView: View { | |
| @AppStorage("number") var number = 1 | |
| var body: some View { | |
| VStack { | |
| Text("Hello, world! number = \(number)") | |
| .padding() | |
| Button("+1") { |
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 View { | |
| /// Workaround .foregroundColor(nil) not inherit from outter view bug | |
| /// | |
| /// ``` | |
| /// ZStack { | |
| /// Image(systemName: "star.fill") | |
| /// .conditional(foregroundColor: Int.random(in: 1...5) < 2 ? .green : nil) | |
| /// } | |
| /// .foregroundColor(.red) | |
| /// ``` |
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 SwiftUI | |
| public protocol ObservablePropertySource: ObservableObject { | |
| static var shared: Self { get } | |
| } | |
| @propertyWrapper | |
| public struct ObservableProperty<S: ObservablePropertySource, T>: DynamicProperty { | |
| @ObservedObject private var source: S |
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 SwiftUI | |
| private struct OnFirstAppear: ViewModifier { | |
| let perform: () -> Void | |
| @State private var firstTime = true | |
| func body(content: Content) -> some View { | |
| content.onAppear { | |
| if firstTime { |