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 DrawingPath { | |
private var points = [CGPoint]() | |
private var breaks = [Int]() | |
mutating func addPoint(_ point: CGPoint) { | |
points.append(point) | |
} | |
mutating func addBreak() { | |
breaks.append(points.count) |
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
// | |
// SwiftUI+HTML.swift | |
// | |
// Created by Felix Mau on 28.05.21. | |
// Copyright © 2021 Felix Mau. All rights reserved. | |
// | |
import SwiftUI | |
@available(iOS 15.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
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
@propertyWrapper | |
struct AnimatedState<Value> : DynamicProperty { | |
let storage: State<Value> | |
let animation: Animation? | |
init( | |
value: Value, | |
animation: Animation? = nil | |
) { | |
self.storage = State<Value>(initialValue: value) |
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
// full recipe at https://swiftuirecipes.com/blog/swiftui-text-with-html-via-nsattributedstring | |
extension Text { | |
init(html htmlString: String, | |
raw: Bool = false, | |
size: CGFloat? = nil, | |
fontFamily: String = "-apple-system") { | |
let fullHTML: String | |
if raw { | |
fullHTML = htmlString | |
} else { |
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 ToggledExampleView_Previews: PreviewProvider { | |
static var previews: some View { | |
DebuggingToggledExampleView() | |
} | |
} | |
// MARK: - Toggled Source | |
protocol ToggleInterface { | |
associatedtype ValueType |
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 Status: Decodable { | |
case completed, inProgress | |
case other(String) | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let value = try container.decode(String.self) | |
switch value { | |
case "completed": self = .completed |
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 | |
struct ContentView: View { | |
@StateObject private var state: ContentViewState = .init() | |
var body: some View { | |
VStack { | |
Text(state.count.description) | |
Button("Count Up") { state.countUp() } | |
Button("Reset") { state.reset() } | |
} |
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 UIView { | |
func springIn(duration: TimeInterval = 0.5, delay: Double = 0, fromScale: CGFloat = 0.6) { | |
self.layer.removeAllAnimations() | |
self.alpha = 1 | |
self.transform = CGAffineTransform(scaleX: fromScale, y: fromScale) | |
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.5, initialSpringVelocity: 3.0, options: [.curveEaseInOut, .allowUserInteraction], animations: { | |
self.transform = .identity | |
}) | |
} |
NewerOlder