Skip to content

Instantly share code, notes, and snippets.

View jwilling's full-sized avatar

Jonathan Willing jwilling

View GitHub Profile
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
@jwilling
jwilling / NSString+IBNMetrics.h
Created January 3, 2014 01:19
Better string metrics on OS X.
#import <Foundation/Foundation.h>
@interface NSString (IBNMetrics)
- (CGSize)ibn_sizeConstrainedToSize:(CGSize)size font:(NSFont *)font;
- (CGSize)ibn_sizeWithFont:(NSFont *)font;
@end
@jwilling
jwilling / LBHView.h
Last active February 6, 2018 12:44
A terrible, terrible hack to toggle AppKit's destruction of layer modifications.
#import <Cocoa/Cocoa.h>
@interface LBHView : NSView
/// This property controls whether the view can indirectly control its
/// backing layer's properties, specifically the following:
/// `affineTransform`
/// `anchorPoint`
///
/// These properties cannot be modified on the layer during the time that
@jwilling
jwilling / gist:8160367
Created December 28, 2013 15:09
NSViewLayerContentsRedrawCrossfade on 10.8
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 4.f;
context.allowsImplicitAnimation = YES;
[view.layer addAnimation:CATransition.animation forKey:@"contents"];
view.layer.contents = someImage;
} completionHandler:nil];
@jwilling
jwilling / QTMAsyncOperationQueue.h
Created October 29, 2013 04:17
Simple block-based serial queue for asynchronous operations.
//
// QTMAsyncOperationQueue.h
// Quantum
//
// Created by Jonathan Willing on 10/28/13.
// Copyright (c) 2013 AppJon. All rights reserved.
//
#import <Foundation/Foundation.h>
@jwilling
jwilling / JNWThrottledBlock.h
Last active October 26, 2020 17:02
Simple throttling of blocks using dispatch sources.
#import <Foundation/Foundation.h>
@interface JNWThrottledBlock : NSObject
// Runs the block after the buffer time _only_ if another call with the same identifier is not received
// within the buffer time. If a new call is received within that time period the buffer will be reset.
// The block will be run on the main queue.
//
// Identifier and block must not be nil.
+ (void)runBlock:(void (^)())block withIdentifier:(NSString *)identifier throttle:(CFTimeInterval)bufferTime;
@jwilling
jwilling / JNWAsyncGroupOperation.m
Created July 11, 2013 00:55
basic async operations
#import <Foundation/Foundation.h>
typedef void (^JNWGroupAsyncOperationCompletion)();
@interface JNWGroupAsyncOperation : NSObject
// The completion block that will be fired when all operations have completed.
@property (nonatomic, copy) void(^groupCompletion)();
// Adds an asynchronous operation and starts it on the main thread. The completion block _must_
@jwilling
jwilling / gist:5929321
Last active December 19, 2015 08:59
Handling errors when using toProperty:onObject:.
RAC(self.someOrderedSet) = [[[[[[RACAble(self.searchField.text)
filter:^BOOL(NSString *text) {
return (text.length > 0);
}]
map:^id(NSString *text) {
return [Something searchForAutocomplete:text]; // this signal can send errors
}]
switchToLatest]
catchTo:[RACSignal return:[NSArray array]]]
map:^id(NSArray *objects) {
@jwilling
jwilling / gist:4186817
Last active March 5, 2023 22:01
Lets help improve AppKit.

Is AppKit causing you frustration? Instead of just complaining about it, lets try to make it better by compiling a list of specific problems with AppKit. Leave a comment below, and I'll include it in the list.


##NSView##

  • NSView does not have the ability to set an affine transform (rdar://15608609)
  • Controls that have cells (such as NSTextField) do not respond properly when layer-backed. Take NSButton as an example. When not layer-backed, it will animate properly using the animator proxy. When layer-backed, using the animator proxy breaks focus rings (they jump to destination immediately). Currently, directly manipulating the layer of a cell-based control is not supported (and will lead to a broken interface), but is much needed. (rdar://15608822)

##NSViewController##

  • NSViewController could be more useful. It has -loadView but no other lifecycle methods. (rdar://15608948)
@jwilling
jwilling / CustomClipView.m
Last active October 12, 2015 09:08
NSTableView with custom clip view
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (!self) return nil;
self.layer = [CAScrollLayer layer];
self.wantsLayer = YES;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever;
return self;
}