Skip to content

Instantly share code, notes, and snippets.

@janodev
janodev / gist:4683470
Created January 31, 2013 15:06
14589365
#import <Foundation/Foundation.h>
typedef NS_ENUM(unsigned char, MyTreeVisitingOrder) {
MyTreeOrderDepthFirst,
MyTreeOrderValueFirst
};
#define Tree NSObject<MyTree>
@protocol MyTree
@janodev
janodev / Makefile
Last active September 23, 2016 19:47 — forked from boredzo/Makefile
dispatch_once is not reentrant. Use a NSReentrantLock if you want reentrancy.
CC=clang
CFLAGS+=-std=c99 -g
LDFLAGS+=-framework Foundation
dispatch_once_reentrancy_test: dispatch_once_reentrancy_test.o
@janodev
janodev / Animal.h
Created February 16, 2013 02:27
Ways to declare Objective-C variables. See a commented version at http://stackoverflow.com/a/14906215/412916
@interface Animal : NSObject
{
NSObject *iProtected;
@package
NSObject *iPackage;
@private
NSObject *iPrivate;
@protected
NSObject *iProtected2; // default access. Only visible to subclasses.
@public
#import <Foundation/Foundation.h>
// clang -framework Foundation main.m -o main && ./main
int main(int argc, char *argv[]) {
@autoreleasepool {
NSUInteger (^__block factorial)(NSUInteger n);
NSUInteger (^__block __weak weakFactorial)(NSUInteger n);
weakFactorial = factorial = ^ NSUInteger (NSUInteger n) {
return n==0 ? 1 : n * weakFactorial(n-1);
};
@janodev
janodev / NutritionFacts+Builder.m
Last active June 21, 2023 05:26
Objective-C Builder pattern.
@interface NutritionFacts(Builder)
-(NutritionFactsBuilder*)builder;
@end
@implementation NutritionFacts(Builder)
-(NutritionFactsBuilder*)builder {
return [[NutritionFactsBuilder alloc]initWithNutritionFacts:self];
}
@end
@janodev
janodev / gist:5292003
Last active December 15, 2015 16:49 — forked from iamleeg/gist:5290797
This creates an Objective-C object in the stack. ARC code.
#import <Foundation/Foundation.h>
#include <stdlib.h>
#include <objc/runtime.h>
@interface A : NSObject
@property (assign) int meaning;
@end
@implementation A
@janodev
janodev / gist:5332644
Last active December 15, 2015 22:19
Dynamic GCD accessors with resolveInstanceMethod: and dispatch_barrier_async.
#include <objc/runtime.h>
#import <Foundation/Foundation.h>
@interface Hi : NSObject
@end
@implementation Hi {
NSString *something;
}
@janodev
janodev / gist:5341598
Created April 8, 2013 23:44
Text to speech on iOS with private framework.
// Not App Store safe. Only available in real devices.
#define RTLD_LAZY 0x1
#define RTLD_NOW 0x2
#define RTLD_LOCAL 0x4
#define RTLD_GLOBAL 0x8
NSObject *voiceSynthesizer;
void *voiceServices;
@janodev
janodev / MySingleton.h
Last active July 28, 2016 03:19
Singleton pattern with __atribute__ unavailable to prevent the accidental misuse of a singleton. Note that the user is still able to create more instances using runtime functions.
#import <Foundation/Foundation.h>
@interface MySingleton : NSObject
+(instancetype) sharedInstance;
// clue for improper use (produces compile time error)
+(instancetype) alloc __attribute__((unavailable("alloc not available, call sharedInstance instead")));
-(instancetype) init __attribute__((unavailable("init not available, call sharedInstance instead")));
+(instancetype) new __attribute__((unavailable("new not available, call sharedInstance instead")));
#!/bin/bash
# This script builds the iOS and Mac openSSL libraries
# It's expanded from https://github.com/st3fan/ios-openssl
set -xe
# Setup paths to stuff we need
OPENSSL_VERSION="1.0.1e"