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 / 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 {
@import Foundation;
@interface A : NSObject
@end
@interface B : A
@end
// Private objc ivars are really private:
@implementation A
{
@n-b
n-b / TaggedDate.m
Last active November 13, 2015 09:04
NSDates are (sometimes) tagged pointers
@import Foundation;
int main() {
for (int i=0; i<100; i++) {
NSDate * date = NSDate.date;
printf("%p\n",date);
}
}
//
// 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 / ClassDotSyntax.m
Created June 24, 2013 20:24
Sample code for a couple of Radars on dot-syntax: rdar://14250868 Dot syntax on Class methods only compiles with public methods rdar://14250709 Xcode does not always autocomplete the dot-syntax
// The behaviour for dot-syntax is inconsistent in two aspects.
//
// 1. Autocompletion
// @properties and instance methods declared in the @interface block are autocompleted in Xcode with the dot-syntax;
// However class methods and private instance method are not autocompleted, although they are perfectly valid.
//
// Moreover, the class method are suggested in autocompletion after an instance variable.
// (in the example below, that would be instance.classMethod.
//
// Autocompletion should be suggested whenever the syntax is valid.