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 | |
import UIKit | |
public final class HostingView: UIView { | |
public init(@ViewBuilder content: () -> some View) { | |
super.init(frame: .zero) | |
let contentView = UIHostingConfiguration(content: content) | |
.margins(.all, 0) | |
.makeContentView() |
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
// | |
// NSApplication+NSResponderDebug.swift | |
// | |
// Created by Stephan Casas on 3/18/24. | |
// | |
import Cocoa; | |
extension NSApplication { | |
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
#!/opt/homebrew/bin/python3 | |
import re | |
import glob | |
import os | |
import graphviz | |
################################################################################## | |
######### USAGE ######### |
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 { | |
public func discover<T: UIView>( | |
where predicate: @escaping (T) -> Bool = { _ in true }, | |
_ closure: @escaping (T) -> Void | |
) -> some View { | |
overlay( | |
DiscoveryView(predicate: predicate, setup: closure) | |
.frame(width: 0, height: 0) |
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
- In almost all cases where you type `@ObservedObject`, you really want `@StateObject`. | |
If you need to support iOS 13, use `@State` on parent and pass value into child with `@ObservedObject` to simulate `@StateObject`. | |
Pass arguments to that model in `onAppear`. Example: https://github.com/ra1028/SwiftUI-Hooks/blob/main/Sources/Hooks/HookScope.swift#L39-L41 | |
``` | |
.onAppear { | |
model.onAppear(userTag: userTag) | |
} | |
.onDisappear { | |
model.onDisappear() |
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
extension Color { | |
/// Return a random color | |
static var random: Color { | |
return Color( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1) | |
) | |
} | |
} |
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 | |
struct ContentView: View { | |
var body: some View { | |
HStack { | |
Text("Hello") | |
.padding() | |
.background(.blue) | |
.overlay { | |
Color.yellow |
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
//: [Previous](@previous) | |
import Foundation | |
import SwiftUI | |
import Combine | |
//: Current Value Subject is a value, a publisher and a subscriber all in one | |
let currentValueSubject = CurrentValueSubject<Bool, Never>(true) | |
print(currentValueSubject.value) |
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
// | |
// CAAnimation+BlockCallback.swift | |
// | |
import UIKit | |
// | |
// Modified from http://onedayitwillmake.com/blog/2016/06/caanimation-completion-callback-block/ | |
// Updated for Swift 4 syntax | |
// All credit to the original author (Mario Gonzalez) |
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
// Copyright (c) 2019, SeatGeek, Inc | |
// All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are met: | |
// | |
// * Redistributions of source code must retain the above copyright notice, this | |
// list of conditions and the following disclaimer. | |
// | |
// * Redistributions in binary form must reproduce the above copyright notice, |
NewerOlder