This file contains 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
dispatch_block_t RecursiveBlock(void (^block)(dispatch_block_t recurse)) | |
{ | |
// assuming ARC, so no explicit copy | |
return ^{ block(RecursiveBlock(block)); }; | |
} | |
typedef void (^OneParameterBlock)(id parameter); | |
OneParameterBlock RecursiveBlock1(void (^block)(OneParameterBlock recurse, id parameter)) | |
{ |
This file contains 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 | |
enum CoroutineState { | |
case Fresh, Running, Blocked, Canceled, Done | |
} | |
struct CoroutineCancellation: ErrorType {} | |
class CoroutineImpl<InputType, YieldType> { | |
let body: (yield: YieldType throws -> InputType) throws -> Void |
This file contains 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 <objc/runtime.h> | |
class Printer { | |
public: | |
const char *str; | |
~Printer() { puts(str); } | |
}; |
This file contains 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
func effIt<Target, Result>(_ keypath: KeyPath<Target, Result>) -> (Target) -> Result { | |
return { $0[keyPath: keypath] } | |
} | |
struct Foo { | |
var x: Int | |
var y: Int | |
} |
This file contains 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> | |
int main(int argc, char **argv) { | |
auto global = ^{ NSLog(@"Hello, world!"); }; | |
auto captures = ^{ NSLog(@"argc is %d", argc); }; | |
NSLog(@"global: %@ - captures: %@", global, captures); | |
NSLog(@"(void *)global: %p - (void *)captures: %p", (void *)global, (void *)captures); | |
id globalCopy = [global copy]; | |
id capturesCopy = [captures copy]; |
This file contains 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
func ??<T>(lhs: T?, rhs: @autoclosure () throws -> Never) rethrows -> T { | |
guard let value = lhs else { try rhs() } | |
return value | |
} | |
func ??<T>(lhs: T?, rhs: () throws -> Never) rethrows -> T { | |
guard let value = lhs else { try rhs() } | |
return value | |
} |
This file contains 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
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
Dl_info info; | |
int success = dladdr(main, &info); | |
if (success == 0) abort(); | |
printf("main is at %p and the mach-o header that contains it is at %p\n", main, info.dli_fbase); | |
} |
This file contains 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
class C {} | |
protocol P where Self: C { | |
var x: Int { get } | |
var y: Int { get } | |
} | |
extension P { | |
var x: Int { return 42 } | |
} |
This file contains 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
// clang -fobjc-arc -framework Foundation runtime-class.m | |
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
@interface Person : NSObject | |
- (id)initWithFirstName: (NSString *)firstName lastName: (NSString *)lastName age: (NSUInteger)age; |
This file contains 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> | |
// .h file | |
struct MyConstantsStruct | |
{ | |
NSString *foo; | |
NSString *bar; |