Instantly share code, notes, and snippets.

View TempDir.swift
// tl;dr: FileManager.default.url(for:in:appropriateFor:create:) has unexpected behavior in Simulator and creates temporary folders outside the tmp/ directory.
let tmpDirClassic = NSTemporaryDirectory()
print("tmpDirClassic: \(tmpDirClassic)")
// This is the same code, just syntax sugar for NSTemporaryDirectory()
// https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/FileManager.swift#L1420-L1422
let tmpDirClassicNewShim = FileManager.default.temporaryDirectory
print("tmpDirClassicNewShim: \(tmpDirClassicNewShim)")
// Simulator: /Users/steipete/Library/Developer/CoreSimulator/Devices/31C05637-B9C9-482C-A6CE-D063A7CECF64/data/Containers/Data/Application/A68D11A4-88BA-4FCF-A8B1-D102945D0740/tmp/
View UIKit+iOSMac.h
#import <Foundation/Foundation.h>
@class NSString, UHASToolbarItem;
__attribute__((weak_import)) @interface _UIWindowToolbarItem : NSObject
@property(readonly, copy, nonatomic) NSString *label;
@property(readonly, copy, nonatomic) NSString *identifier;
- (id)initWithIdentifier:(id)arg1;
View TestCaseSubclass.m
static void PSPDFFixiOS12AccessibilityTestCrash(void) {
let accessibilityLoaderClass = NSClassFromString(@"UIAccessibilityInformationLoader");
let accessibilitySEL = NSSelectorFromString(@"_loadAccessibilityInformationOnMainThread:");
__block IMP originalIMP = pspdf_swizzleSelectorWithBlock(accessibilityLoaderClass, accessibilitySEL, ^(id _self, BOOL onMainThread) {
@try {
((void (*)(id, SEL, BOOL))originalIMP)(_self, accessibilitySEL, onMainThread);
} @catch (NSException *exception) {
NSLog(@"Exception received: %@", exception);
if ([exception.name isEqualToString:NSInvalidArgumentException] && [exception.reason containsString:@"_accessibilityLoadAccessibilityInformation"]) {
NSLog(@"Ignoring IOS 12b5 weirdness...");
View Confused.m
// Works
__auto_type queue = dispatch_queue_create("com.pspdfkit.test", DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(queue, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0));
// Crashes with EXC_BAD_INSTRUCTION
// I guess this fails because the global queues already have an autorelease pool?
__auto_type queue2 = dispatch_queue_create("com.pspdfkit.test", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
dispatch_set_target_queue(queue2, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0));
View gist:a759b56dc1b5d94ba5b3c03ddd00a1ed
Process: Tweetbot [58303]
Path: /Applications/Tweetbot.app/Contents/MacOS/Tweetbot
Identifier: com.tapbots.TweetbotMac
Version: 2.5.4 (25400)
App Item ID: 557168941
App External ID: 824334033
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Tweetbot [58303]
User ID: 501
View DispatchQueueSurprise.m
- (void)testDispatchConcurrentExecutionWithNamedQueuesRaw {
let expectation = [self expectationWithDescription:@"Concurrent execution must happen"];
let semaphore = dispatch_semaphore_create(0);
// global queue, concurrent
let attributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_DEFAULT, 0);
let defaultQueue = dispatch_queue_create("com.pspdfkit.default-concurrent", attributes);
// serial sub-queues that dispatch to concurrent queue
let queue1 = dispatch_queue_create("com.pspdfkit.queue1", DISPATCH_QUEUE_SERIAL);
View gist:8c683dd840596e34dcb9159373cea933
Class Methods:
+ (Class) safeCategoryBaseClass; (0x12c470134)
+ (BOOL) _old_unswizzled_automaticallyNotifiesObserversForKey:(id)arg1; (0x1150df5a0)
+ (id) _old_unswizzled_keyPathsForValuesAffectingValueForKey:(id)arg1; (0x1150df620)
+ (id) requiredStoreLibraryPersonalizationProperties; (0x118daaeff)
+ (void) mf_clearLocks; (0x11a41d09e)
+ (void) _accessibilityCalDetailStringForEvent:(id)arg1 inLine1:(id*)arg2 inLine2:(id*)arg3 inLine3:(id*)arg4 inLine4:(id*)arg5; (0x127db7c6e)
+ (void) _accessibilityCalGetHourDesignatorsForAM:(id*)arg1 andPM:(id*)arg2; (0x127d1e7bb)
+ (BOOL) _accessibilityCalSpaceBetweenDesignatorsAndHour; (0x127d1e7cb)
+ (BOOL) _accessibilityCalHourDesignatorsAreBeforeHour; (0x127d1e7ec)
View gist:2ec99bca9dd01e405f9fd7db17472cb5
Process: PSPDFFoundation-TestHost-iOS [95495]
Path: /Users/USER/Library/Developer/CoreSimulator/Devices/1694A397-7C29-4470-A3A0-9A3E350DB19E/data/Containers/Bundle/Application/3A6309AC-3045-4D7C-9E83-006339C933C6/PSPDFFoundation-TestHost-iOS.app/PSPDFFoundation-TestHost-iOS
Identifier: PSPDFFoundation-TestHost-iOS
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [93146]
Responsible: PSPDFFoundation-TestHost-iOS [95495]
User ID: 502
Date/Time: 2017-10-30 15:37:04.800 -0400
View gist:6a467947cf0db4eb0be0cd90af1990d5
Process: PSPDFFoundation-TestHost-iOS [15960]
Path: /Users/USER/Library/Developer/CoreSimulator/Devices/0AE503AA-1EFF-4FC4-A1B3-D64B83DD1059/data/Containers/Bundle/Application/774DC2FD-74EF-4F79-B700-EEB70410267F/PSPDFFoundation-TestHost-iOS.app/PSPDFFoundation-TestHost-iOS
Identifier: PSPDFFoundation-TestHost-iOS
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [10769]
Responsible: PSPDFFoundation-TestHost-iOS [15960]
User ID: 502
Date/Time: 2017-10-20 00:02:36.697 -0700
View gist:84fa68a373be22ef2737c0b3441ac94e
Process: Xcode [4032]
Path: /Applications/Xcode-beta.app/Contents/MacOS/Xcode
Identifier: Xcode
Version: 9.0 (13238.4)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [4032]
User ID: 501
Date/Time: 2017-08-28 10:28:44.078 +0200