Skip to content

Instantly share code, notes, and snippets.

Chris Dzombak cdzombak

Block or report user

Report or block cdzombak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View block-verify.m
NYTCompletionBlock completion = ^(id result) {};
id completionMock = [OCMockObject partialMockForObject:completion];
[[[completionMock expect] copy] andReturn:completion];
id sut = [[NYTXXX alloc] initWithCompletion:completionMock];
#pragma unused (sut)
[completionMock verify];
View CDZWeak.h
//
// CDZWeak.h
// https://gist.github.com/cdzombak/844e887ed4bdb933a905
//
// Created by Chris Dzombak on 3/22/15.
// Copyright (c) 2015 Chris Dzombak. All rights reserved.
//
#ifndef CDZWeak_h
#define CDZWeak_h
View CDZIdioms.h
//
// CDZIdioms.h
// https://www.dzombak.com/blog/2015/02/Tiny-Swift-idioms-in-ObjC.html
//
// Created by Chris Dzombak on 3/21/15.
// Copyright (c) 2015 Chris Dzombak. All rights reserved.
//
#ifndef CDZIdioms_h
#define CDZIdioms_h
@cdzombak
cdzombak / lazy_get.m
Created Feb 27, 2015
simple ObjC lazy getter macro
View lazy_get.m
#import <Foundation/Foundation.h>
#define lazy_get(TYPE, NAME, VALUE) \
@synthesize NAME = _##NAME; \
- (TYPE)NAME { if (!_##NAME) _##NAME = (VALUE); return _##NAME; }
// example usage follows:
@interface LazyThing : NSObject
@cdzombak
cdzombak / as.m
Created Feb 26, 2015
swift-style as in ObjC
View as.m
#import <Foundation/Foundation.h>
#define as_checked(EXPR, KLASS) ({ id _obj = EXPR; NSCAssert([_obj isKindOfClass:[KLASS class]], @"Cannot cast %@ to %@", NSStringFromClass([_obj class]), NSStringFromClass([KLASS class])); _obj; })
#define as_option(EXPR, KLASS) ({ id _obj = EXPR; if (![_obj isKindOfClass:[KLASS class]]) _obj = nil; _obj; })
@interface NSObject(As)
- (instancetype)asChecked:(Class)klass;
@cdzombak
cdzombak / iflet.m
Last active Jan 7, 2016
if-let in ObjC
View iflet.m
#import <Foundation/Foundation.h>
#define iflet(LHS, RHS) \
for (id obj_ = (RHS); obj_ != nil;) \
for (LHS = (obj_ ?: (RHS)); obj_ != nil; obj_ = nil)
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *x = nil;
NSString *y = @"y";
@cdzombak
cdzombak / gist:16351244498cdb2f383c
Created Feb 1, 2015
Effective Organization for Developers, talk abstract
View gist:16351244498cdb2f383c

You have a lot of responsibilities and plenty of to-dos to keep track of. Add in your email and Instapaper and it can feel impossible to make any progress. But it's not! In this talk we’ll discuss basic principles you can use to organize yourself, stay atop your responsibilities, and destress at the same time. We’ll also cover some common organizational pitfalls that we as programmers can fall into, and we’ll briefly discuss tooling, including the pros and cons of using a tool like OmniFocus.

View Router.swift
public class Router : NSObject {
typealias VCPushBlock = (UIViewController) -> (Void)
init(context: NSManagedObjectContext, pushBlock: VCPushBlock) {
// ...
}
convenience init(context: NSManagedObjectContext, owningViewController: UIViewController) {
self.init(context: context, pushBlock: {
owningViewController.navigationController?.pushViewController($0, animated: true)
@cdzombak
cdzombak / Router.swift
Created Jan 22, 2015
Swift compilation issue that took some of my time today. Solution: https://gist.github.com/cdzombak/431cea0a4c0ced8042a5
View Router.swift
public class Router : NSObject {
typealias VCPushBlock = (UIViewController) -> (Void)
init(context: NSManagedObjectContext, pushBlock: VCPushBlock) {
// ...
}
convenience init(context: NSManagedObjectContext, owningViewController: UIViewController) {
self.init(context: context, pushBlock: {
owningViewController.navigationController?.pushViewController($0, animated: true)
You can’t perform that action at this time.