Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
extension View {
func pipe<R>(@ViewBuilder _ f: (Self) -> R) -> R {
f(self)
}
}
struct ContentView: View {
@State var flag: Bool = false
@chriseidhof
chriseidhof / Package.swift
Created June 29, 2021 09:42
Toml To Yaml
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "TomlToYaml",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.executable(
import SwiftUI
import Yams
extension String {
var yamlToJSON: String {
do {
guard let parsed = try Yams.load(yaml: self) else { return "" }
let data = try JSONSerialization.data(withJSONObject: parsed, options: [.sortedKeys, .prettyPrinted])
return String(decoding: data, as: UTF8.self)
} catch {
// Simplified version of https://gist.github.com/anandabits/d9494d14fef221983ff4f1cafa318d47#file-areequatablyequal-swift
func isEqual(x: Any, y: Any) -> Bool {
func f<LHS>(_ lhs: LHS) -> Bool {
let p = Wrapper<LHS>.self as? AnyEquatable.Type
return p?.isEqual(x, y) ?? false
}
return _openExistential(x, do: f)
}
/// Takes an absolute path and fits it inside the proposed rectangle.
struct FittingShape: Shape {
var absolutePath: Path
func path(in rect: CGRect) -> Path {
let p = absolutePath
let boundingRect = p.boundingRect
let scale = min(rect.width/boundingRect.width, rect.height/boundingRect.height)
let scaled = p.applying(.init(scaleX: scale, y: scale))
let scaledBoundingRect = scaled.boundingRect
@chriseidhof
chriseidhof / ContentView.swift
Created February 20, 2021 17:19 — forked from steipete/ContentView.swift
FB9013209: SwiftUI: Preview and actual layout differ in this example. (SwiftUI Bug)
//
// ContentView.swift
// Shared
//
// Created by Peter Steinberger on 20.02.21.
//
import SwiftUI
struct SettingsGroup<Content: View>: View {
//: A Cocoa based Playground to present user interface
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("Highlight :")
.background(Color.green)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)
//
// ContentView.swift
// WeatherWidget
//
// Created by Chris Eidhof on 20.01.21.
//
import SwiftUI
struct MyGuide: AlignmentID {
import SwiftUI
let items = ["Basic", "Advanced", "Ultra"]
struct ContentView: View {
@State var value: Int = 0
var body: some View {
VStack {
Picker(selection: $value, label: Text("Mode:")) {