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
/// A type that has an "empty" representation. | |
public protocol EmptyRepresentable { | |
static func empty() -> Self | |
} | |
extension Array: EmptyRepresentable { | |
public static func empty() -> Array<Element> { | |
return Array() | |
} | |
} |
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 CoreGraphics | |
extension NSScreen { | |
var displayID: CGDirectDisplayID { | |
return deviceDescription["NSScreenNumber"] as? CGDirectDisplayID ?? 0 | |
} | |
} |
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
// UIInterfaceOrientationMask vs. UIInterfaceOrientation | |
// As far as I know, a function like this isn't available in the API. I derived this from the enum def for | |
// UIInterfaceOrientationMask. | |
inline BOOL OrientationMaskSupportsOrientation(UIInterfaceOrientationMask mask, UIInterfaceOrientation orientation) { | |
return (mask & (1 << orientation)) != 0; | |
} |
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
@implementation UIImage (scale) | |
/** | |
* Scales an image to fit within a bounds with a size governed by | |
* the passed size. Also keeps the aspect ratio. | |
* | |
* Switch MIN to MAX for aspect fill instead of fit. | |
* | |
* @param newSize the size of the bounds the image must fit within. | |
* @return a new scaled image. |
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 | |
/** | |
hack to avoid crashes on window close, and remove the window from the | |
NSApplication stack, ie: avoid leaking window objects | |
*/ | |
fileprivate final class WindowDelegate: NSObject, NSWindowDelegate { | |
func windowShouldClose(_ sender: NSWindow) -> Bool { | |
NSApp.removeWindowsItem(sender) | |
return true |
OlderNewer