This file contains hidden or 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 | |
import SwiftUI | |
// Hacky workaround, use at your own risk and all that | |
struct BottomSheetPresenter<Content>: UIViewRepresentable where Content: View{ | |
let label: String | |
let content: Content | |
let detents: [UISheetPresentationController.Detent] | |
init(_ label: String, detents: [UISheetPresentationController.Detent], @ViewBuilder content: () -> Content) { |
This file contains hidden or 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 URLSession extension that fetches data from a URL and decodes to some Decodable type. | |
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL) | |
// Note: this requires Swift 5.5. | |
extension URLSession { | |
func decode<T: Decodable>( | |
_ type: T.Type = T.self, | |
from url: URL, | |
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, | |
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData, | |
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate |
This file contains hidden or 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
/* | |
IMPORTANT: Change the fonts on lines 31-35 to make this work the way you want! | |
*/ | |
:root { | |
--dark0: #2e3440; | |
--dark1: #3b4252; | |
--dark2: #434c5e; |
This file contains hidden or 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 wiggling() -> some View { | |
modifier(WiggleModifier()) | |
} | |
} | |
struct WiggleModifier: ViewModifier { | |
@State private var isWiggling = false |
This file contains hidden or 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 Tristate: ExpressibleByNilLiteral, ExpressibleByBooleanLiteral { | |
case maybe | |
case no | |
case yes | |
init(nilLiteral: Void) { | |
self = .maybe | |
} | |
init(booleanLiteral value: Bool) { |
This file contains hidden or 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
// | |
// Feel free to use this code in your project. | |
// Inspired by SO answer https://stackoverflow.com/a/65743126 | |
// Uses DeviceKit as a dependency https://github.com/devicekit/DeviceKit | |
// | |
import Foundation | |
import MessageUI | |
import DeviceKit |
This file contains hidden or 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 | |
/// Represents a single `NSLayoutConstraint` | |
enum LayoutAnchor { | |
case constant(attribute: NSLayoutConstraint.Attribute, | |
relation: NSLayoutConstraint.Relation, | |
constant: CGFloat) | |
case relative(attribute: NSLayoutConstraint.Attribute, | |
relation: NSLayoutConstraint.Relation, |
This file contains hidden or 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
//To configure the contents of the HUD | |
struct HUDConfig { | |
var text: String | |
var icon: Image | |
var autohide = true | |
static func success(_ s: String) -> HUDConfig { | |
return HUDConfig(text: s, icon: Image(systemName: "checkmark.circle.fill")) | |
} | |
} |
This file contains hidden or 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 | |
enum PreviewProviderMode: CaseIterable { | |
/// Use for a light appearance preview. | |
case lightMode | |
/// Use for a dark appearance preview. | |
case darkMode | |
This file contains hidden or 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
/// iOS 13 version here: https://gist.github.com/aheze/bd4e1990dbeda66e60c00c6341451930 | |
/// Note: iOS 13 version has a "bug" where adding a second finger freezes the touch event | |
/// More details here: https://developer.apple.com/forums/thread/660070 | |
/// Thanks @brentbrinkley for discovering the bug! | |
/// if you're on iPad Swift Playgrounds and you put all of this code in a seperate file, | |
/// you need to make everything public so that the compiler detects it. | |
/// the possible states of the button | |
public enum ButtonState { |