View parser-validator.swift
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 UIKit | |
// Almost pseudocode, but should be possible to write in proper Swift | |
// MARK: High-Level APIs | |
// Decodes the document. By default, ignores errors and warnings. | |
func decode(data: Data, isStrict: Bool = false) -> throws OpenAPI.Document { | |
let parser = JSONDecoder().decoder(DocumentParser.self, from: data) | |
// Or maybe be even more granular: "strict", "ignoreWarnings", "ignoreAll"? |
View cURLDescription.swift
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
extension URLRequest { | |
public func cURLDescription() -> String { | |
guard let url = url, let method = httpMethod else { | |
return "$ curl command generation failed" | |
} | |
var components = ["curl -v"] | |
components.append("-X \(method)") | |
for header in allHTTPHeaderFields ?? [:] { | |
let escapedValue = header.value.replacingOccurrences(of: "\"", with: "\\\"") | |
components.append("-H \"\(header.key): \(escapedValue)\"") |
View EnvironmentPicker.swift
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
enum APIEnvironment: String, CaseIterable { | |
case dev | |
case test | |
case stage | |
case prod | |
} | |
struct ContentView: View { | |
@State private var selection: APIEnvironment? = env | |
View FocusList.swift
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() |
View PinEdges.swift
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 { |
View StateObject.swift
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() |
View tbd
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 |
View Example.swift
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) | |
} |
NewerOlder