Skip to content

Instantly share code, notes, and snippets.


Alexander Grebenyuk kean

View GitHub Profile
View parser-validator.swift
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
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)\"")
kean / EnvironmentPicker.swift
Created Nov 21, 2021
Code from "Designing an API Client in Swift"
View EnvironmentPicker.swift
enum APIEnvironment: String, CaseIterable {
case dev
case test
case stage
case prod
struct ContentView: View {
@State private var selection: APIEnvironment? = env
kean /
Created Nov 9, 2021
Pulse Pro 1.4 Release Notes

Pulse 1.4.0

Nov 8, 2021


  • You can now switch to a Network view using the main Toolbar. It has several advantages. For example, when you switch, it keeps your selection, filters, and other perferences. You can now also close the sidebar if you don't need to switch between devices.
  • Sidebar now displayes your connected devices making it easier to switch between them. Devices and their associated logs are stored persistently. With a context menu, you can open the device in a separate window, show the store in Finder, or remove the device.
  • When you open a log file (.pulse extension), it nows opens in a clean window with no sidebar and with a filename in the navigation title.
View FocusList.swift
import SwiftUI
struct FocusTestApp: App {
var body: some Scene {
WindowGroup {
.commands {
View PinEdges.swift
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
// 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)")
View share.swift
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
extension NSAttributedString {
static func make(html: String, size: CGFloat, color: UIColor) -> NSAttributedString? {
// TODO: Size is configured programatically which means we can
// change it dynamically if needed (aka dynamic type)
View navigation-view.swift
struct ContentView: View {
@State private var isShowingDetailView = false
var body: some View {
NavigationView {
NavigationLink(destination: Text("Second View"), isActive: $isShowingDetailView) {
Text("Show Detail")