Skip to content

Instantly share code, notes, and snippets.

@bagelturf
bagelturf / gist:2707225
Created May 16, 2012 03:52
Crashes in CFRelease of a CALayer
Thread 1, Queue : (null)
#0 0x354b42fc in CFRelease ()
#1 0x323b090c in CA::release_objects(X::List<void const*>*) ()
#2 0x323968ec in CA::Transaction::unlock() ()
#3 0x323c8a34 in CA::Layer::~Layer() ()
#4 0x323c8928 in -[CALayer dealloc] ()
#5 0x04572d2a in -[CALayerAccessibility(SafeCategory) dealloc] ()
#6 0x323996b2 in CALayerRelease ()
#7 0x323a66c0 in CA::Layer::free_transaction(CA::Transaction*) ()
@bagelturf
bagelturf / gist:5543576
Created May 8, 2013 20:54
URLByAppendingPathComponent is 10x slower than URLByAppendingPathComponent:isDirectory:
Running Time Self Symbol Name
519.0ms 3.4% 1.0 -[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:]
459.0ms 3.0% 0.0 -[NSURL getResourceValue:forKey:error:]
456.0ms 3.0% 0.0 CFURLCopyResourcePropertyForKey
454.0ms 2.9% 0.0 _FSURLCopyResourcePropertyForKey
2.0ms 0.0% 2.0 OSSpinLockUnlock$shim
2.0ms 0.0% 2.0 _FSURLEndResourcePropertyCacheAccess
1.0ms 0.0% 1.0 CFRunLoopGetCurrent
55.0ms 0.3% 0.0 -[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:isDirectory:]
2.0ms 0.0% 1.0 -[__NSCFString hasSuffix:]
@bagelturf
bagelturf / nsdecimalnumber.m
Created September 17, 2013 04:03
Using NSNumberFormatter to read in decimal numbers has rounding problems. However decimalNumberWithString can't grok currency symbols, so I'm using NSNumberFormatter.
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
NSNumberFormatter *inputFormatter = [[NSNumberFormatter alloc] init];
[inputFormatter setLocale:locale];
[inputFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[inputFormatter setLenient:YES];
[inputFormatter setGeneratesDecimalNumbers:YES];
NSDecimalNumber *a = (NSDecimalNumber *)[inputFormatter numberFromString:@"87.85"];
NSDecimalNumber *b = [NSDecimalNumber decimalNumberWithString:@"87.85"];
non-ARC recursive block
void __block (^batchReaderRecursive)(NSUInteger position, NSUInteger count); // Used for the recursive reference
void (^batchReader)(NSUInteger position, NSUInteger count); // Used to reference the block
batchReaderRecursive = batchReader = [^(NSUInteger position, NSUInteger count) {
dispatch_async(background queue, ^{
// Do work, update position abd count
@bagelturf
bagelturf / gist:85dab3297557e1b237507460acb0ffba
Last active April 23, 2016 03:00
Why do I get error: cannot convert value of type 'Int' to expected argument type 'XX' on line 10?
class XX {
func a(b: Int) -> Int {
return b
}
var functionA = a
func run() {
print("\(functionA(1))") // Needs (self) after functionA
@bagelturf
bagelturf / gist:b048f41debfa2385b23adfea5ee261dc
Last active April 27, 2016 05:25
Why do I need "as V?" ?
import Cocoa
private struct Bin<V> {
var key: Int
var value: V?
}
public class Thing<V> {