Skip to content

Instantly share code, notes, and snippets.

@n-b
n-b / main.m
Created March 15, 2012 14:12
properties are strong by default now.
//
// main.m
// testproperties
//
// Created by Nicolas Bouilleaud on 15/03/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@n-b
n-b / main.m
Created March 27, 2012 09:45
A minimal test for a NSNetService bug (rdar://11018654). The TXTRecordData property is never updated.
//
// clang main.m -framework Foundation && ./a.out
#import <Foundation/Foundation.h>
/****************************************************************************/
#pragma mark -
@interface Advertiser : NSObject
@end
@n-b
n-b / NSRunLoop+TimeOutAndFlag.h
Created April 4, 2012 08:29
A simple runloop addition to ease Asynchronous Unit Tests in ObjC
//
// NSRunLoop+TimeOutAndFlag.h
//
//
@interface NSRunLoop (TimeOutAndFlag)
- (void)runUntilTimeout:(NSTimeInterval)delay orFinishedFlag:(BOOL*)finished;
@end
@n-b
n-b / PropertyMacros.h
Created April 15, 2012 18:45
KVC compile-time checking macros
//
// PropertyMacros.h
//
//
// Created by Nicolas Bouilleaud on 12/04/12,
// using ideas by Uli Kusterer (http://orangejuiceliberationfront.com/safe-key-value-coding/)
// Laurent Deniau (https://groups.google.com/forum/?fromgroups#!topic/comp.std.c/d-6Mj5Lko_s)
// and Nick Forge (http://forgecode.net/2011/11/compile-time-checking-of-kvc-keys/)
//
//
@n-b
n-b / orderedset-kvo-test.m
Created November 22, 2012 15:20
NSOrderedSet KVO Collection Operators tests
//
// clang orderedset-kvo-test.m -framework Foundation && ./a.out
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
int main ()
{
@n-b
n-b / orderedsets-more-kvc.m
Created November 23, 2012 08:39
More KVC weirdness with NSOrderedSets
//
// clang orderedsets-more-kvc.m -framework Foundation && ./a.out
//
#import <Foundation/Foundation.h>
int main ()
{
@autoreleasepool {
//
// clang -framework Foundation NSConstantString_test.m; ./a.out; rm ./a.out
//
#import <Foundation/Foundation.h>
#define PrintObjectInfo(obj) \
do{id _obj = ( obj );\
printf("%-61s %-20s %-16p %ld\n", #obj" :", [NSStringFromClass([_obj class]) UTF8String], _obj, [_obj retainCount]);\
}while(0);
@n-b
n-b / foo.m
Last active December 13, 2015 20:58
Test retain cycle with block parameters
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@end
@implementation Foo
- (void) setBar:(void(^)(void))block {}
- (void) doBaz:(void(^)(void))block{}
@end
@n-b
n-b / selfcompile.m
Last active April 29, 2019 03:43
A simple self-compiling objective-c file
/*/../bin/ls > /dev/null
COMPILED=${0%.*}
clang $0 -o $COMPILED -framework Foundation;
$COMPILED; rm $COMPILED; exit;
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
@n-b
n-b / NBResponderChainUtilities.h
Last active August 3, 2021 10:08
Chain Responder Debugging Methods
//
// NBResponderChainUtilities.h
//
// Created by Nicolas @ bou.io on 19/04/13.
//
#import <UIKit/UIKit.h>
@interface UIView (NBResponderChainUtilities)
- (UIView*) nb_firstResponder; // Recurse into subviews to find one that responds YES to -isFirstResponder