This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface BNRDiggyDict : NSObject | |
// React to object indexing. Would be nice to have a @protocol for this | |
- (id) objectForKeyedSubscript: (id) key; | |
- (void) setObject: (id) thing forKeyedSubscript: (id<NSCopying>) key; | |
// And for fun, it also can react to scalar indexing. | |
// Returns the N'th key of the top-level collection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <mach/mach_time.h> // for mach_absolute_time() and friends | |
// clang -g -Wall -framework Foundation -o equaltime equaltime.m | |
// clang -g -arch i386 -Wall -framework Foundation -o equaltime equaltime.m | |
CGFloat BNRTimeBlock (void (^block)(void)) { | |
mach_timebase_info_data_t info; | |
if (mach_timebase_info(&info) != KERN_SUCCESS) return -1.0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <mach/mach_time.h> // for mach_absolute_time() and friends | |
// clang -g -Wall -framework Foundation -o timestarts timestarts.m | |
CGFloat BNRTimeBlock (void (^block)(void)) { | |
mach_timebase_info_data_t info; | |
if (mach_timebase_info(&info) != KERN_SUCCESS) return -1.0; | |
uint64_t start = mach_absolute_time (); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "stdio.h" | |
// clang -g -Wall -o scanstop scanstop.m | |
static short intArray[] = { 1, 1, 2, 3, 5, 7, 12, 19, 31 }; | |
static char *ravenArray[] = { "once", "upon", "a", "midnight", "dreary" }; | |
typedef struct Groovy { | |
int value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -g -Wall -framework Foundation -o bool bool.m | |
// Are these two integers different? YES if so, NO if not | |
// (even though it says YES and NO, it LIES! Can actualy return a range | |
// of non-YES values) | |
static BOOL different (int thing1, int thing2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -g -Wall -fobjc-arc -framework Foundation -o serial serial.m | |
static id makePlistObjects (void) { | |
NSMutableDictionary *top = [NSMutableDictionary dictionary]; | |
[top setObject: @"Hi I'm a string" forKey: @"string"]; | |
[top setObject: [NSNumber numberWithInt: 23] forKey: @"number"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -fobjc-arc -Wall -Wformat -Weverything -Wno-format-nonliteral -framework Foundation -o log log.m | |
// Compiler likes explicit function prototypes prior to first use. | |
// Add an attribute to get additional checking from the compiler | |
extern void QuietLog (NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); | |
// !!! The attribute above isn't warning like it should, but NSLog's _is_ working. | |
// This is NSLog's attribute. I'm currently baffled. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -Weverything -framework Foundation -o string-fun string-fun.m | |
int main (void) { | |
@autoreleasepool { | |
{ | |
// Split and join | |
NSString *splitString = @"hello:-(there:-(everybody"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
// clang -Weverything -fobjc-arc -framework Cocoa -o notification notification.m | |
void QuietLog (NSString *format, ...); | |
void StartSpying (void); | |
void StopSpying (void); | |
void QuietLog (NSString *format, ...) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -g -framework Foundation -o mutant mutant.m | |
int main (void) { | |
NSMutableDictionary *mutable = [[NSMutableDictionary alloc] init]; | |
NSDictionary *immutable = [[NSDictionary alloc] init]; | |
NSLog (@"mutable responds to set object for key: %d", | |
[mutable respondsToSelector: @selector(setObject:forKey:)]); |
OlderNewer