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 | |
@main | |
struct FocusTestApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
.commands { | |
MessageCommands() |
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
public protocol LayoutItem { // `UIView`, `UILayoutGuide` | |
var superview: UIView? { get } | |
} | |
extension UIView: LayoutItem {} | |
extension UILayoutGuide: LayoutItem { | |
public var superview: UIView? { owningView } | |
} | |
public struct Alignment { |
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
// Version 1: Using initializer directly | |
struct ContentView: View { | |
@State var count = 0 | |
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() | |
var body: some View { | |
VStack { | |
Text("container: \(count)") | |
.padding() |
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
asd |
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
public struct ImageView: View { | |
@ObservedObject var image: FetchImage | |
public var body: some View { | |
ZStack { | |
Rectangle().fill(Color.gray) | |
image.view? | |
.resizable() | |
.aspectRatio(contentMode: .fill) | |
} |
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 Future | |
import Combine | |
public extension Future { | |
var publisher: Combine.Future<Value, Error> { | |
Combine.Future { fulfill in | |
self.on(success: { | |
fulfill(.success($0)) | |
}, failure: { | |
fulfill(.failure($0)) |
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 SearchView: View { | |
@ObservedObject var viewModel: SearchViewModel | |
var body: some View { | |
VStack { | |
TextField("Search", text: $viewModel.query) | |
List(viewModel.songs) { | |
Text($0.name) | |
} | |
} |
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 speculative _ViewRendererHost implementation which uses Mirror (Swift reflection) to find all | |
// of the dynamic properties (`DynamicProperty`) associated with a given view (`View`), observe | |
// the changes to these properties and automatically refresh the view whenever any of these property change. | |
protocol _DynamicProperty { | |
var objectWillChange: AnyPublisher<Void, Never> { get } | |
} | |
extension ObservedObject: _DynamicProperty { | |
var objectWillChange: AnyPublisher<Void, Never> { |