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 | |
extension View { | |
func pipe<R>(@ViewBuilder _ f: (Self) -> R) -> R { | |
f(self) | |
} | |
} | |
struct ContentView: View { | |
@State var flag: Bool = false |
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
// 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( |
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 | |
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 { |
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
// 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) | |
} |
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
/// 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 |
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
// | |
// ContentView.swift | |
// Shared | |
// | |
// Created by Peter Steinberger on 20.02.21. | |
// | |
import SwiftUI | |
struct SettingsGroup<Content: View>: View { |
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 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) |
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
// | |
// ContentView.swift | |
// WeatherWidget | |
// | |
// Created by Chris Eidhof on 20.01.21. | |
// | |
import SwiftUI | |
struct MyGuide: AlignmentID { |
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 | |
let items = ["Basic", "Advanced", "Ultra"] | |
struct ContentView: View { | |
@State var value: Int = 0 | |
var body: some View { | |
VStack { | |
Picker(selection: $value, label: Text("Mode:")) { |