This file contains 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 | |
class Counter { | |
var count = 0 | |
} | |
extension EnvironmentValues { | |
@Entry var counter = Counter() | |
} | |
struct ContentView: View { |
This file contains 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
/* | |
The following feature is 100% pure Swift code. It compiles for a multitude of platforms, | |
include iOS, macOS, Linux, Windows, Wasm, and more. It encapsulates all of the logic | |
and behavior for the feature so that the view can concentrate on just the UI by reading | |
state from the model and invoking methods on the model. | |
*/ | |
import Dependencies | |
import FactClient | |
import Perception |
This file contains 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
/* | |
The @AppStorage property wrapper does not fully work unless installed | |
directly in a view. In particular, it does not work when used in an | |
observable object. | |
Paste the following into a fresh project, run it in the simulator, | |
and notice that tapping the "Toggle model.isOn" button causes the view | |
to update propertly, but tapping the "Toggle UserDefaults directly" | |
button does not. This means that writing directly to user defaults | |
does cause @AppStorage to update, _unless_ @AppStorage is used in the |
This file contains 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 SyncUpDetailView: View { | |
- @Bindable var model: SyncUpDetailModel | |
+ @Bindable var store: StoreOf<SyncUpDetail> | |
var body: some View { | |
Form { | |
Section { | |
Button { | |
- model.startMeetingButtonTapped() | |
+ store.send(.startMeetingButtonTapped) |
This file contains 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
# FB12969716 | |
// FB: `Form` and | |
// | |
// Paste this into a fresh SwiftUI project's ContentView.swift to see a bug with `Form` views with | |
// conditional child views that use `@State`. | |
// | |
// 1. Tap "Toggle" to show the child view with a new model | |
// 2. Tap "+" in the child view to increment the model's state from 0 to another number | |
// 3. Tap "Toggle" two times to hide the child and then show it again |
This file contains 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 | |
@Observable | |
class CounterModel { | |
var count = 0 | |
} | |
struct CounterView: View { | |
let model: CounterModel | |
var body: some View { | |
Text(self.model.count.description) |
FB12101395, apple/swift issue #64974
Run the following code in a simulator, tap the “Go” button, and notice that the application freezes:
import SwiftUI
struct ContentView: View {
var body: some View {
This file contains 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
// A fix for https://github.com/AvdLee/TaskGroupsResultBuilder/blob/main/TaskGroups/TaskResultBuilder.swift | |
// to handle cancellation. | |
@resultBuilder | |
struct TaskBuilder { | |
static func buildExpression<Success: Sendable>(_ task: Task<Success, Never>) -> [Task<Success, Never>] { | |
[task] | |
} | |
static func buildBlock<Success: Sendable>(_ tasks: [Task<Success, Never>]...) -> [Task<Success, Never>] { |
Is it possible for Xcode/linker to automatically link -ObjC when linking static libraries that contain Swift or ObjC code?
Without that it is possible for a protocol conformance in a static library to be seemingly stripped from the library. For example, if you have the following protocol hierarchy in a static library:
protocol P {}
NewerOlder