Skip to content

Instantly share code, notes, and snippets.

@kylesluder
kylesluder / assert.c
Created August 30, 2012 00:14
Optional assertion description argument
#include <stdio.h>
static inline void _AssertionFailed(char *expr, char *reason)
{
if (!reason || *reason == '\0')
printf("Assertion failed: %s\n", expr);
else
printf("Assertion failed: %s (Reason: %s)\n", expr, reason);
}
@kylesluder
kylesluder / AppDelegate.m
Created July 3, 2012 21:45
Cannot animate fade-in of NSView using animator proxy (r.11801145)
@implementation AppDelegate
@synthesize window = _window;
@synthesize box = _box;
@synthesize addButton = _addButton;
@synthesize useDummyAnimationGroup = _useDummyAnimationGroup;
- (void)_prepareForFadeIn;
{
[_box setAlphaValue:0];
@kylesluder
kylesluder / prop.m
Created June 4, 2012 23:32
Property redeclaration error when widened in multiple extensions
// clang -c -o /dev/null prop.m
#import <Foundation/NSObject.h>
@interface Obj : NSObject /*Public*/
@end
@interface Obj ( /*Internal*/ )
@property (readonly, retain, nonatomic) NSObject *prop;
@end
@kylesluder
kylesluder / proptest.m
Created February 15, 2012 23:44
Unexpected readonly/readwrite @Property and @synthesize behavior
#import <Foundation/NSObject.h>
@interface Foo : NSObject
@property (readonly, assign) id bar;
@end
@interface Foo (Internal)
@kylesluder
kylesluder / Xcode4Beachball.sample
Created March 29, 2011 17:18
Xcode 4 sometimes beachballs at the "Building dSYMs" stage when I hit Cmd-R.
Sampling process 363 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Xcode (pid 363) every 1 millisecond
Process: Xcode [363]
Path: /Xcode4/Applications/Xcode.app/Contents/MacOS/Xcode
Load Address: 0x100000000
Identifier: com.apple.dt.Xcode
Version: 4.0.1 (99)
Build Info: IDEApplication-990000~49
Code Type: X86-64 (Native)
@kylesluder
kylesluder / typeof-selector.m
Created December 16, 2010 21:09
An idea for using typeof on selector types
// It would be great if we had a typeof analogue that worked for selectors and evaluated to the type of the method that matches that selector.
@interface Foo : NSObject
- (NSString *)aMethod:(CGFloat)arg1 withArgs:(NSString *)arg2;
@end
void exampleOne() {
Foo *f = [Foo new];
NSString *s = (__typeof_msg__(f, @selector(aMethod:withArgs:))objc_msgSend)(f, 0, @"String");
NSNumber *n = (__typeof_msg__(f, @selector(aMethod:withArgs:))objc_msgSend)(f, 1.0, @"Hi"); // error: returns NSString*
@kylesluder
kylesluder / SynthDemo.m
Created November 25, 2010 20:41
Demo of synthesized ivar scope
#import <Foundation/Foundation.h>
@interface Foo : NSObject
{ /* Notice there's nothing here */ }
@property(nonatomic,retain) id someVar;
- (void)unrelated;
@end
#import <Foundation/Foundation.h>
@protocol Foo
@property (readonly, nonatomic) int blah;
@end
typedef void (^bk)(void);
@interface Foo : NSObject<Foo>
{ int v; }
- (bk)makeBlock:(id<Foo>)otherFoo;
@kylesluder
kylesluder / OQColor.m
Created October 19, 2010 00:08
Version of OQColorGetComponents that goes through a linear RGB color space
OQLinearRGBA OQGetColorComponents(NSColor *c)
{
static dispatch_once_t once;
static NSColorSpace *linearRGBColorSpace;
dispatch_once(&once, ^{
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
linearRGBColorSpace = [[NSColorSpace alloc] initWithCGColorSpace:cgColorSpace];
CGColorSpaceRelease(cgColorSpace);
OBASSERT_NOTNULL(linearRGBColorSpace);
#import <Foundation/Foundation.h>
class CppClass
{
public:
void doIt();
}
;
@interface Foo : NSObject