Skip to content

Instantly share code, notes, and snippets.

View revblaze's full-sized avatar

Justin Bush revblaze

View GitHub Profile
@carlynorama
carlynorama / JavascriptPlaytime.xcplaygroundpage
Created February 6, 2016 15:34
Including Javascript in a Swift File, Simple and Clean.
//: Embedding JavaScript in Swift
import UIKit
import JavaScriptCore
var str = "Hello, playground"
//from http://nshipster.com/javascriptcore/
let context1 = JSContext()
@msewell
msewell / SegueHandlerType.swift
Last active October 3, 2022 16:45
SegueHandlerType for Swift 3
/* The SegueHandlerType pattern, as seen on [1, 2], adapted for the changed Swift 3 syntax.
[1] https://developer.apple.com/library/content/samplecode/Lister/Listings/Lister_SegueHandlerType_swift.html
[2] https://www.natashatherobot.com/protocol-oriented-segue-identifiers-swift/
*/
protocol SegueHandlerType {
// `typealias` has been changed to `associatedtype` for Protocols in Swift 3.
associatedtype SegueIdentifier: RawRepresentable
import Foundation
import Gridicons
import UIKit
import WebKit
class WebViewController: UIViewController {
let webView = WKWebView()
let progressView = WebProgressView()
let toolbar = UIToolbar()
let titleView = NavigationTitleView()
@unnamedd
unnamedd / MacEditorTextView.swift
Last active May 26, 2024 17:49
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@revblaze
revblaze / .gitignore
Last active November 29, 2022 12:24
Universal Xcode .gitignore for iOS, iPadOS, macOS and tvOS development
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
.toolbar {
ToolbarItemGroup {
Button(action: {}, label: {
Image(systemName: "sidebar.left")
})
Spacer()
Button(action: {}, label: {
Image(systemName: "play.fill")
})
Button(action: {}, label: {
@jordansinger
jordansinger / Settings.swift
Created February 20, 2021 18:30
iOS 6 Settings built in SwiftUI
//
// Settings.swift
// Settings
//
// Created by Jordan Singer on 2/20/21.
//
import SwiftUI
struct Settings: View {
@importRyan
importRyan / whenHovered.md
Last active July 9, 2024 19:51
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