Skip to content

Instantly share code, notes, and snippets.

// Test 2 failed
// Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver decodeObjectForKey:]:
// value for key (NSAttributes) contains too many nested (NSDictionary)s"
// UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver decodeObjectForKey:]: value for
// key (NSAttributes) contains too many nested (NSDictionary)s}
// Test 3 succeeded
// Finished
import Cocoa
//
// Lock.swift
//
// Created by Seth Willits on 11/23/15.
// Copyright © 2015 Araelium Group. All rights reserved.
//
import Foundation
#import <Carbon/Carbon.h>
static NSLock * gKeyTranslateLock = nil;
CFStringRef LiDTS_CopyTranslateHotKey(UInt16 virtualKeyCode)
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
gKeyTranslateLock = [[NSLock alloc] init];
If an NSScrollView with a vertical ruler view has "Show Horizontal Scroller" turned on, then the content view
(like an NSTextView) is laid out to be extra wide and appears *under* the vertical ruler view. The content view
is laid out to be the width of the scrollview plus the width of the ruler view, is placed at the X origin of
the scroll view so it overlaps the ruler view, and is scrolled all the way to the right, so the left side
appears cut off.
This only happens on Mojave.
Steps to Reproduce:
Have an NSTextView with a vertical ruler view and "Show Horizontal Scroller" turned on. See the example
Process: Screenflick [15975]
Path: /Volumes/*/Screenflick.app/Contents/MacOS/Screenflick
Identifier: com.araeliumgroup.screenflick
Version: ???
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Screenflick [15975]
User ID: 501
Date/Time: 2018-10-05 08:45:33.797 -0700
@swillits
swillits / OSVersion.swift
Last active April 12, 2018 20:37
Convenient macOS/iOS/etc version checking at runtime
//
// OSVersion.swift
// Created by Seth Willits on 4/12/18.
//
// if runtimeOSVersion.isAtLeast(10, 12) { ... }
import Foundation
var runtimeOSVersion: OperatingSystemVersion {
@swillits
swillits / EnforceSubclassImplementations.h
Created February 2, 2018 05:36
EnforceSubclassImplementations – Used to enforce that your class hierarchy overrides required methods
//
// EnforceSubclassImplementations.h
//
// Created by Seth Willits on 2/9/15.
// Copyright (c) 2015. All rights reserved.
//
#import <Foundation/Foundation.h>
#ifdef __cplusplus
//
// main.m
// SupportedPixelFormats
//
// Created by Seth Willits on 12/11/17.
// Copyright © 2017 Araelium Group. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <CoreVideo/CoreVideo.h>
@swillits
swillits / FlippingClipView.swift
Created December 14, 2017 18:59
Flip an NSScrollView Properly
/// Pins the document to the top-left of the clip view
final class FlippingClipView: NSClipView {
override func constrainBoundsRect(_ proposedBounds: NSRect) -> NSRect {
var constrained = super.constrainBoundsRect(proposedBounds)
guard let documentHeight = documentView?.frame.height else {
return constrained
}
@swillits
swillits / AGKVOReceptionist.h
Last active April 26, 2017 03:54
Obj-C Preferences Observation
typedef void (^KVOReceptionistBlock)(NSString *keyPath, id object, NSDictionary *change);
@interface AGKVOReceptionist : NSObject
{
id _observedObject;
NSString * _observedKeyPath;
KVOReceptionistBlock _handler;
BOOL _cancelled;
}