Skip to content

Instantly share code, notes, and snippets.

View nckh's full-sized avatar

Greg de J nckh

View GitHub Profile
@sebjvidal
sebjvidal / ViewController.swift
Created May 28, 2024 16:39
UICustomViewMenuElement Demo
//
// ViewController.swift
// UIMenu-Demo
//
// Created by Seb Vidal on 28/05/2024.
//
import UIKit
class ViewController: UIViewController {
@steventroughtonsmith
steventroughtonsmith / VisionViewPlaygroundApp.swift
Created September 21, 2023 19:22
Trivial visionOS non-rectangular window content layout example
//
// VisionViewPlaygroundApp.swift
// VisionViewPlayground
//
// Created by Steven Troughton-Smith on 21/09/2023.
//
import SwiftUI
@main
import UIKit
import SwiftUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let box = UIView()
box.frame = CGRect(x: (view.bounds.width / 2.0) - 100.0, y: 0.0, width: 100.0, height: 100.0)
box.backgroundColor = .systemGreen
struct ContentView: View {
@State var selected: Bool = false
var body: some View {
Color.clear
.frame(width: 900, height: 400)
.toolbar {
ToolbarItem {
Button(action: {}, label: {
@peterfriese
peterfriese / Color+Codable.swift
Created March 19, 2021 11:00
Making Swift's Color codable
//
// Color+Codable.swift
// FirestoreCodableSamples
//
// Created by Peter Friese on 18.03.21.
//
import SwiftUI
// Inspired by https://cocoacasts.com/from-hex-to-uicolor-and-back-in-swift
@importRyan
importRyan / whenHovered.md
Last active March 2, 2025 12:00
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@robksawyer
robksawyer / excludedActivityTypes.swift
Last active December 12, 2024 10:37
A list of UIActivity.ActivityType for modern apps.
let excludedActivityTypes = [
UIActivity.ActivityType.print,
UIActivity.ActivityType.openInIBooks,
UIActivity.ActivityType.copyToPasteboard,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.assignToContact,
UIActivity.ActivityType.copyToPasteboard,
UIActivity.ActivityType.mail,
UIActivity.ActivityType.markupAsPDF,
UIActivity.ActivityType.postToFacebook,
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
1. In capabilities need to turn on the iCloud and tick the iCloud Documnet in services. Choose the container and note
down its name. (because while setting up settings inside info.plist we. need to set the NSUbiquitousContainers key value
same as this name).
2. We need to define the iCloud Drive Container that we are going to use inside info.plist
<key>NSUbiquitousContainers</key>
<dict>
<key>this has to be same as selected containers name inside entitlement</key>
<dict>
@tzmartin
tzmartin / show-hn.md
Created August 8, 2020 18:01
How to Submit a Show HN

How to Submit a "Show HN"

If you're sharing your own work and there's a way to try it out, put "Show HN" in the title. Make sure you've read the Show HN guidelines: https://news.ycombinator.com/showhn.html.

Posts without URLs get penalized, so when you submit, put your site in the URL field and leave the text field blank.

Add a comment to the thread giving the backstory of how you came to work on this, and explaining what's different about it. That tends to seed discussion in a good direction.

Include a clear statement of what your project is or does. If you don't, the discussion will consist of "I can't tell what this is". >