Skip to content

Instantly share code, notes, and snippets.

View timothycosta's full-sized avatar

Timothy Costa timothycosta

View GitHub Profile
#! /usr/bin/swift
//
// - This is just some AppKit boilerplate to launch a window.
//
import AppKit
@available(OSX 10.15, *)
class AppDelegate: NSObject, NSApplicationDelegate {
let window = NSWindow()
let windowDelegate = WindowDelegate()
@ethanhuang13
ethanhuang13 / FacebookAuth.swift
Last active March 28, 2024 08:24
FacebookAuth is for iOS app developers who need to support Facebook login but don't want to use the official SDK
//
// FacebookAuth.swift
// GitHub: ethanhuang13
// Twitter: @ethanhuang13
import AuthenticationServices
import SafariServices
/*
Updated:
@IanKeen
IanKeen / EnvironmentValues.swift
Last active January 5, 2024 08:49
SwiftUI: Peek at/extract hidden environment values
import Foundation
import SwiftUI
extension EnvironmentValues {
public func value<T>(_: T.Type = T.self, forKey key: String) -> T? {
guard let value = first(where: { name($0, equals: key) }) else {
print("No EnvironmentValue with key '\(key)' found.")
return nil
}
@krzyzanowskim
krzyzanowskim / NSRange+NSTextContentManager.swift
Created February 15, 2022 18:03
NSRange TextKit2 helpers
extension NSRange {
static let notFound = NSRange(location: NSNotFound, length: 0)
var isEmpty: Bool {
length == 0
}
init(_ textRange: NSTextRange, in textContentManager: NSTextContentManager) {
let offset = textContentManager.offset(from: textContentManager.documentRange.location, to: textRange.location)