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 AppState { | |
var value1: Int = 0 | |
var value2: Int = 0 | |
var value3: Int = 0 | |
} | |
extension AppState { | |
struct Injection: EnvironmentKey { | |
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 ContentView: View { | |
// The local view's state encapsulated in one container: | |
@State private var state = ViewState() | |
// The app's state injection | |
@Environment(\.injected) private var injected: AppState.Injection | |
var body: some View { | |
Text("Value: \(state.value)") |
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 CustomView: View { | |
@EnvironmentObject var appState: Deduplicated<AppState, Snapshot> | |
var body: some View { | |
Text("Value: \(appState.value)") | |
} | |
} | |
let view = CustomView() | |
.environmentObject(appState |
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 CustomView: View { | |
@EnvironmentObject var appState: AppState | |
var body: some View { | |
Text("Value: \(appState.value)") | |
} | |
} | |
let view = CustomView() | |
.environmentObject(appState) |
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
object.objectWillChange | |
.delay(for: .nanoseconds(1), scheduler: RunLoop.main) | |
.compactMap { _ in makeSnapshot() } | |
.prepend(makeSnapshot()) | |
.removeDuplicates() | |
.dropFirst() | |
.sink { [weak self] _ in | |
self?.objectWillChange.send() | |
} |
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 CustomView: View { | |
@EnvironmentObject var appState: AppState | |
private var prevValue: Int | |
var body: some View { | |
self.prevValue = appState.value | |
return Text("Value: \(appState.value)") | |
} | |
} |
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
class AppState: ObservableObject { | |
@Published var value: Int = 0 | |
} | |
struct CustomView: View { | |
@EnvironmentObject var appState: AppState | |
var body: some View { | |
Text("Value: \(appState.value)") | |
} |
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
// | |
// Deduplicated.swift | |
// CountriesSwiftUI | |
// | |
// Created by Alexey Naumov on 17.12.2019. | |
// Copyright © 2019 Alexey Naumov. All rights reserved. | |
// | |
import Foundation | |
import Combine |
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 ContentView: View { | |
@State var selectedAnnotation: MKAnnotationID? | |
@State var annotations: [MKAnnotation] = [] | |
var body: some View { | |
ZStack { | |
MapView(selected: self.$selectedAnnotation, annotations: self.$annotations) | |
ForEach(self.annotations) { annotation in | |
NavigationLink( | |
destination: AnnotationDetailsView(annotation: annotation), |
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
Average FPS | ElementView Body Calls | Cumulative Body Calculation Time | |
---|---|---|---|
20 | 255000 | 1430 ms |