This file contains hidden or 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
static BOOL (^imagesDifferByCGDataProviderComparison)(CGImageRef, CGImageRef) = ^(CGImageRef a, CGImageRef b) { | |
BOOL result = NO; | |
CGDataProviderRef aDataProvider = CGImageGetDataProvider(a); | |
CGDataProviderRef bDataProvider = CGImageGetDataProvider(b); | |
// It turns out that the CGDataProvider's pages are set copy-on-write, so these calls are not nearly as expensive as you think. | |
CFDataRef aData = CGDataProviderCopyData(aDataProvider); | |
CFDataRef bData = CGDataProviderCopyData(bDataProvider); | |
This file contains hidden or 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
NSMutableData *dataObj = [NSMutableData dataWithLength:length]; | |
objc_setAssociatedObject(self, key, dataObj, OBJC_ASSOCIATION_RETAIN); | |
void *data = [dataObj mutableBytes]; |
This file contains hidden or 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
// Example ignores concurrency protection on internalRefCount for brevity. | |
// Not compatible with ARC, for obvious reasons (but could be implemented in part with a non-ARC category?). | |
@interface Foo () | |
@property (nonatomic, assign) NSUInteger internalRefCount; | |
@end | |
@implementation Foo |
This file contains hidden or 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
// | |
// NSCoder+NNSecureRectCoding.h | |
// Switch | |
// | |
// Created by Scott Perry on 07/06/13. | |
// Copyright © 2013 Scott Perry. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
This file contains hidden or 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
// | |
// NNMainThreadGuard.m | |
// | |
// Mostly taken from the commercial iOS PDF framework http://pspdfkit.com and Switch https://github.com/numist/Switch. | |
// Copyright © 2013 Peter Steinberger and Scott Perry. All rights reserved. | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// |
This file contains hidden or 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
// Built for ARC, remove the __bridge and it should work in MRC as well. | |
void *NNCFAutorelease(CFTypeRef cfObject) | |
{ | |
if (cfObject) { | |
static Class arp = Nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
arp = NSClassFromString(@"NSAutoreleasePool"); | |
Assert(arp); | |
}); |
This file contains hidden or 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 <objc/runtime.h> | |
#import <stdlib.h> | |
// declare some of the Objective-C runtime's private parts where we can see them | |
typedef struct _NXMapTable NXMapTable; | |
extern NXMapTable *gdb_objc_realized_classes; | |
extern void *NXMapInsert(NXMapTable *table, const void *key, const void *value); | |
@implementation NSObject (Poser) |
This file contains hidden or 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 "memoize.h" | |
@implementation Example | |
- (id)null; | |
{ | |
return NNMemoize(^{ | |
sleep(1); | |
return [NSNull null]; | |
}); |
This file contains hidden or 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
/** | |
Provides the ability to verify key paths at compile time. | |
If "keyPath" does not exist, a compile-time error will be generated. | |
Example: | |
// Verifies "isFinished" exists on "operation". | |
NSString *key = SQKeyPath(operation, isFinished); | |
// Verifies "isFinished" exists on self. |
This file contains hidden or 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 <UIKit/UIKit.h> | |
@protocol NNApplicationSubscriber <NSObject> | |
@optional | |
- (void)applicationDidBecomeActive:(UIApplication *)application; | |
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame; | |
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation; | |
- (void)applicationDidEnterBackground:(UIApplication *)application; | |
- (void)applicationDidFinishLaunching:(UIApplication *)application; |