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 URLRequest { | |
public enum HTTPMethod: String { | |
case get = "GET" | |
case put = "PUT" | |
case post = "POST" | |
case delete = "DELETE" | |
case head = "HEAD" | |
case options = "OPTIONS" | |
case trace = "TRACE" |
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
public class MouseTrackingView: NSView { | |
public var callback: ((Bool) -> Void)? | |
private var trackingArea: NSTrackingArea? | |
public override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} |
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 User: Identifiable { | |
var id: Int | |
var firstName: String | |
var lastName: String | |
} | |
struct UserRow: View { | |
var user: User |
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
public class SheetAnimator: NSObject, NSViewControllerPresentationAnimator { | |
private var animationUUID: UUID? | |
public func animatePresentation(of viewController: NSViewController, from fromViewController: NSViewController) { | |
let containerView = fromViewController.view | |
let sheetView = viewController.view | |
let uuid = UUID() | |
animationUUID = uuid |
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 | |
@main | |
struct DemoVibrancyApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} |
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
class ObjA { | |
var isOn = false | |
} | |
struct ContentView: View { | |
// Because this is not an observed object, the UI in this view should theoretically never update | |
let obj = ObjA() | |
var body: some 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
import Cocoa | |
import SwiftUI | |
public extension View { | |
func bindWindow(_ window: Binding<NSWindow?>) -> some View { | |
return background(WindowAccessor(window)) | |
} | |
} | |
public struct WindowAccessor: NSViewRepresentable { |
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 | |
class Coordinator: ObservableObject { | |
let item = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) | |
init() { | |
let view = NSHostingView(rootView: Text("Hello from SwiftUI").fixedSize()) | |
item.button?.addSubview(view) | |
view.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ |
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 ContentView: View { | |
var body: some View { | |
Image(nsImage: NSImage(named: .init(NSImage.applicationIconName))!) | |
.resizable() | |
.frame(width: 100, height: 100) | |
.tapWithHighlight(onTap: { | |
print("Tap") | |
}, onLongPress: { | |
print("Long Press") | |
}) |
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 | |
@main | |
struct SwiftApp: App { | |
@State var someState = false | |
var body: some Scene { | |
WindowGroup { | |
Rectangle() |
OlderNewer