Skip to content

Instantly share code, notes, and snippets.

View dmaclach's full-sized avatar

dmaclach dmaclach

View GitHub Profile
@dmaclach
dmaclach / main.m
Last active November 29, 2018 05:55
Create an Objective C Class at runtime
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
Class myClass = objc_allocateClassPair([NSObject class], "MyClass", 0);
IMP methodIMP = imp_implementationWithBlock(^(id self) {
return @"Hello";
});
if (!class_addMethod(myClass, @selector(description), methodIMP, "@@:")) {
//
// main.m
// signaltest
//
// Created by Dave MacLachlan on 11/12/18.
// Copyright © 2018 Dave MacLachlan. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <pthread.h>