Skip to content

Instantly share code, notes, and snippets.

func fetch1(where predicateFormat: String, _ args: CVarArg...) {
// using: public convenience init(format predicateFormat: String, _ args: CVarArg...)
let predicate = NSPredicate(format: predicateFormat, args)
print("fetch1 predicate: \(predicate)")
}
func fetch2(where predicateFormat: String, _ args: Any...) {
// Using: public init(format predicateFormat: String, argumentArray arguments: [Any]?)
let predicate = NSPredicate(format: predicateFormat, argumentArray: args)
print("fetch2 predicate: \(predicate)")
function current_git_branch
sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
end
// weak-strong dance by shadowing self
foo { [weak self] in
guard let `self` = self else { return }
self.bar()
}
@js
js / gist:9277611
Created February 28, 2014 19:09
You shouldn't use objc exceptions for flow control, among many reasons they're a tad slow.
// Output on this particular Mac
//
// Exceptions took 5.054922
// BOOL return + NSError took 0.251062
//
#import <Foundation/Foundation.h>
#import <mach/mach_time.h>
static inline void TimeDuration(NSString *description, NSUInteger runs, dispatch_block_t block)
@js
js / gist:6138910
Created August 2, 2013 10:23
RACBacktrace dealloc crash
This file has been truncated, but you can view the full file.
(lldb) racbt
error: Trying to put the stack in unreadable memory at: 0x10f23ef80.
(lldb) bt
* thread #15: tid = 0x2cd18a, 0x00007fff90136fe6 libobjc.A.dylib`objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*>, objc::DenseMapInfo<unsigned long> >::find(objc_object* const&) + 4, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x10f23eff8)
frame #0: 0x00007fff90136fe6 libobjc.A.dylib`objc::DenseMap<objc_object*, unsigned long, true, objc::DenseMapInfo<objc_object*>, objc::DenseMapInfo<unsigned long> >::find(objc_object* const&) + 4
frame #1: 0x00007fff90136f5b libobjc.A.dylib`_objc_rootReleaseWasZero + 126
frame #2: 0x00007fff9014f6f1 libobjc.A.dylib`-[NSObject release] + 17
frame #3: 0x00000001001fbe53 ReactiveCocoa`-[RACBacktrace .cxx_destruct](self=0x0000000102188800, _cmd=0x00007fff8e87e360) + 51 at RACBacktrace.m:153
@js
js / gist:4773884
Created February 12, 2013 22:07
Trying to wrap my head around ReactiveCocoa, by adding a repository list tableview to the GHAPIDemo sample project
// GHDUserViewController.m in the
// Take 1
- (id)initWithUserAccount:(GHGitHubUser *)user {
// .. snip ..
[[[RACSignal
merge:@[[self fetchUser], [self fetchRepos], [self fetchOrgs]]]
finally:^{
@strongify(self);