Skip to content

Instantly share code, notes, and snippets.

View adamkaplan's full-sized avatar

Adam adamkaplan

View GitHub Profile
// Missing 'result unused' warning demo
// Correct: expect.beNil();
// Wrong: expect.beNil;
#import <Foundation/NSObject.h>
#define expect [EXPExpect new]
@interface EXPExpect : NSObject
- (void(^)(void)) beNil;
@adamkaplan
adamkaplan / UsageExample.m
Last active September 5, 2015 00:29
Exploratory examination of a way to prevent accidental retain cycles in blocks.
//
// YFObjCUtils.c
//
// Created by Adam Kaplan on 7/31/15.
// Licensed under the MIT license.
//
@implementation UsageExample
- (void)usageMethod {
@adamkaplan
adamkaplan / Timer.m
Last active August 29, 2015 14:16
Xcode Timer Snippet.
{
uint64_t t_start = mach_absolute_time();
<#code#>
uint64_t t_end = mach_absolute_time();
struct mach_timebase_info t_info;
mach_timebase_info(&t_info);
double_t elapsed = (t_end - t_start) * t_info.numer / (t_info.denom * (double_t)1e6);
NSLog(@"Elapsed: %fms", elapsed);
}
@adamkaplan
adamkaplan / DeDupeExample
Last active August 29, 2015 14:14
Complete Example Code
- (AFHTTPRequestOperation *)GET:(NSString *)urlString
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation*,id))success
failure:(void (^)(AFHTTPRequestOperation*,NSError*))failure
{
NSCAssert([NSThread isMainThread], @"must execute on the main thread");
NSURL *url = [[NSURL URLWithString:urlString relativeToURL:self.baseURL] absoluteString];
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"GET"
@adamkaplan
adamkaplan / gist:20a697fe171d0eeca9dd
Created December 23, 2014 04:16
Disable warnings on a single call
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (config->queuePointer && config->queuePointer == dispatch_get_current_queue()) {
#pragma clang diagnostic pop