Skip to content

Instantly share code, notes, and snippets.

extern crate libc;
use libc::uintptr_t;
type Sel = libc::uintptr_t;
enum ObjcObject {}
type Class<'a> = &'a ObjcObject;
type Id<'a> = &'a ObjcObject;
type NSObjectClass<'a> = Class<'a>;
#![feature(macro_rules)]
extern crate libc;
extern crate sync;
use std::cast::transmute;
use std::c_str::CString;
use std::sync::atomics::{ AtomicUint, INIT_ATOMIC_UINT, SeqCst };
type Sel = uint;
enum ObjcObject {}
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
typedef id (^FLazyProxyResolver)();
@interface FLazyProxy : NSProxy
@end
@interface FLazyProxy () {
// Would an instance created from C++ be safe to pass to C and vice versa?
struct Name {
int x, y, z;
#ifdef __cplusplus
int foo() { return x+y+z; }
#endif
}
@fjolnir
fjolnir / flip.mm
Last active August 29, 2015 14:02
- (NSDictionary *)cy_flippedDictionary
{
NSArray * const keys = [self allKeys];
NSArray * const vals = [self objectsForKeys:keys notFoundMarker:[NSNull null]];
return [NSDictionary dictionaryWithObjects:keys forKeys:vals];
}
protocol TypeEquality {
typealias From
typealias To
func apply(a: From) -> To
}
struct Refl<X> : TypeEquality {
typealias From = X
typealias To = X
func apply(a: From) -> To {
# Compile localized nibs
require "tmpdir"
ibtool = "#{ENV["DEVELOPER_BIN_DIR"]}/ibtool"
xib_dir = "#{ENV["PROJECT_DIR"]}/Fii/ja.lproj"
str_dir = "#{ENV["PROJECT_DIR"]}/Foo/en.lproj"
out_dir = "#{ENV["BUILT_PRODUCTS_DIR"]}/Foo.app/en.lproj"
Dir.mktmpdir do |tmpdir|
NSMapTable *attributes;
for(id path in PSVGPathsFromSVGString(svg, &attributes)) {
CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = (__bridge CGPathRef)path;
NSDictionary *attrs = [attributes objectForKey:path];
layer.strokeColor = (__bridge CGColorRef)attrs[@"strokeColor"];
layer.lineWidth = [attrs[@"strokeWidth"] floatValue];
layer.fillColor = (__bridge CGColorRef)attrs[@"fillColor"];
__weak MyView *self_ = self;
int const fdes = open([path fileSystemRepresentation], O_RDONLY);
_fileWatcher = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fdes,
DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE,
GlobalQueue);
dispatch_source_set_event_handler(_fileWatcher, ^{
unsigned long l = dispatch_source_get_data(_fileWatcher);
if(l & DISPATCH_VNODE_DELETE || l & DISPATCH_VNODE_WRITE) {
dispatch_source_cancel(_fileWatcher);
NSLog(@"Reloading %@", path);
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
#import <ffi/ffi.h>
#import <sys/mman.h>
// Wrapper closure called as a result of a message to `initWith..`
static void _ai_closure(ffi_cif * const aCif, id * const aoRet, void * const aArgs[], NSArray * const paramInfo);
static ffi_closure *_ai_ffi_allocClosure(void ** const codePtr);