Skip to content

Instantly share code, notes, and snippets.

defaults write com.apple.finder QLEnableXRayFolders 1
@interface NSNumber (Enumeration)
- (void)times:(void (^)(NSUInteger index, BOOL *stop))block;
@end
@bencochran
bencochran / gist:5647603
Last active March 5, 2023 21:55
Block, threads, ivars, ARC, yay!
// 1.
// “Safe” but retain cycle.
[self setCompletionBlock:^{
NSLog(@"1: %@", self->_foo);
}];
// 2.
// Unsafe. Could dereference nil.
__weak BCThing *weakSelf = self;
//
// MOAnnotatedCalendarView.h
// MOKit
//
// Created by Ben Cochran on 9/4/13.
// Copyright (c) 2013 Ben Cochran. All rights reserved.
//
#import "MOCalendarView.h"
#!/usr/bin/env ruby
#
# This script can be used to check the in-store availability of the iPhone 5S.
# By default, it searches for all AT&T models. You can change this by editing
# the MY_DEVICES array below. While the Apple API supports searching for
# multiple devices at once, there is a limit.
#
# Once you have properly configured the MY_DEVICES array, you can run this script
# from the terminal. It takes a single parameter, which should be the zip code you
# wish to use for your search.
@bencochran
bencochran / Playground.swift
Last active August 29, 2015 14:06
Swift specificity
import Foundation
func doStuff(item: Any) {
println("Do stuff with this: \(item)")
}
class Foo {
func doStuff() {
doStuff(self) // <- Won’t compile. “Cannot convert 'Foo' to type '() -> ()'”
}
@bencochran
bencochran / MonolithViewController.swift
Last active September 12, 2015 04:45 — forked from asmallteapot/MonolithViewController.swift
Handling storyboard segues with enumerations in Swift
class MonolithViewController: UIViewController {
enum InnerSegueType: String {
case WebView
case Inspector
case Gadget = "SomeNameMismatch"
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
guard let identifier = segue.identifier,
let segueType = InnerSegueType(rawValue: identifier) else {
import Foundation
import ReactiveCocoa
//: # Backoff
//: ## Retry with backoff operator
extension SignalProducerType {
func retryWithBackoff<S: SequenceType where S.Generator.Element == NSTimeInterval>(strategy: S) -> SignalProducer<Value, Error> {
var generator = strategy.generate()