Skip to content

Instantly share code, notes, and snippets.

View mikeabdullah's full-sized avatar

Mike Abdullah mikeabdullah

View GitHub Profile
@mikeabdullah
mikeabdullah / gist:2217400
Created March 27, 2012 15:54
DON'T insert other objects from -awakeFromInsert like this example does
- (void)awakeFromInsert
{
[super awakeFromInsert];
Partner *partner = [NSEntityDescription
insertNewObjectForEntityForName:@"Partner"
inManagedObjectContext:[self managedObjectContext]];
[self setPartner:partner];
}
@mikeabdullah
mikeabdullah / gist:2367295
Created April 12, 2012 13:35
Giving -[NSArrayController add:] a completion block
- (void)addWithCompletionHandler:(void (^)(id object))completionHandler;
{
[self commitEditingWithDelegate:self
didCommitSelector:@selector(controller:didCommit:contextInfo:)
contextInfo:[completionHandler copy]];
}
- (void)controller:(NSArrayController *)editor didCommit:(BOOL)didCommit contextInfo:(void *)contextInfo;
{
void (^completionHandler)(id object) = contextInfo;
@mikeabdullah
mikeabdullah / gist:2480081
Created April 24, 2012 14:24
Passing nil to -isEqualToString:
NSString *string = @"test";
BOOL result = [string isEqualToString:nil];
@mikeabdullah
mikeabdullah / gist:2480093
Created April 24, 2012 14:26
Passing nil to -isEqualToNumber:
NSNumber *number = [NSNumber numberWithInt:0];
BOOL result = [number isEqualToNumber:nil];
@mikeabdullah
mikeabdullah / gist:2480126
Created April 24, 2012 14:32
Calling equality testing methods on nil
NSString *string = nil;
BOOL result = [string isEqualToString:@""];
NSNumber *number = nil;
BOOL result = [number isEqualToNumber:[NSNumber numberWithInt:0]];
@mikeabdullah
mikeabdullah / gist:2836559
Created May 30, 2012 14:08
Etched appearance labels
[[textField cell] setBackgroundStyle:NSBackgroundStyleRaised];
@mikeabdullah
mikeabdullah / gist:3052841
Created July 5, 2012 10:28 — forked from itod/objc_closure.m
Objective-C Closure
// compiled with ARC enabled
NSArray *foo() {
NSMutableArray *res = [NSMutableArray array];
for (int i = 0; i < 3; i++) {
[res addObject:^{
NSLog(@"%d", i);
}];
}
return res;
@mikeabdullah
mikeabdullah / gist:3116322
Created July 15, 2012 11:18
Safely wrapping keychain passwords with NSString/CFString
void freeKeychainContent(void *ptr, void *info)
{
SecKeychainItemFreeContent(NULL, ptr);
}
- (NSString *)passwordFromKeychainItem:(SecKeychainItemRef)keychainItem
{
void *passwordData;
UInt32 passwordLength;
OSStatus status = SecKeychainItemCopyContent(keychainItem,
@mikeabdullah
mikeabdullah / NSManagedObjectContextShim.h
Created July 26, 2012 10:20 — forked from danielctull/ThreadedManagedObjectContext.h
NSManagedObjectContext for iOS 4. Maybe?
/*
NSManagedObjectContextShim.h
NSManagedObjectContextShim
Created by Daniel Tull on 25.07.2012.
Copyright (c) 2012 Daniel Tull. All rights reserved.
@mikeabdullah
mikeabdullah / gist:3200382
Created July 29, 2012 17:22
Power assertion example
// Begin the power assertion
IOPMAssertionID assertionID;
IOReturn asserted = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
kIOPMAssertionLevelOn,
CFSTR("Sandvox Publishing"),
&assertionID);
if (asserted != kIOReturnSuccess) // handle the error; log it or something
// Do your long-running work