Created
April 17, 2019 02:38
-
-
Save nicolas17/6a8ad7fbd7912238d366f47accd274d3 to your computer and use it in GitHub Desktop.
iOS application in C
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 "AppDelegate.h" | |
#import <CoreGraphics/CoreGraphics.h> | |
#import "objc-insanity.h" | |
void initializeAppDelegate() | |
{ | |
Class c = objc_allocateClassPair(objc_getClass("NSObject"), "AppDelegate", 0); | |
class_addProtocol(c, objc_getProtocol("UIApplicationDelegate")); | |
class_addMethod(c, S("application:didFinishLaunchingWithOptions:"), (IMP)didFinishLaunching, "B@:@@"); | |
objc_registerClassPair(c); | |
} | |
BOOL didFinishLaunching(id self, SEL sel, id application, id launchOptions) | |
{ | |
id screen = objc_method(id, TYPE(Class, SEL), objc_getClass("UIScreen"), S("mainScreen")); | |
CGRect bounds = objc_method(CGRect, TYPE(id, SEL), screen, S("bounds")); | |
id window = class_createInstance(objc_getClass("UIWindow"), 0); | |
window = objc_method(id, TYPE(id, SEL, CGRect), window, S("initWithFrame:"), bounds); | |
id viewController = class_createInstance(objc_getClass("UIViewController"), 0); | |
viewController = objc_method(id, TYPE(id, SEL), viewController, S("init")); | |
id color = objc_method(id, TYPE(Class, SEL), objc_getClass("UIColor"), S("yellowColor")); | |
id view = objc_method(id, TYPE(id, SEL), viewController, S("view")); | |
objc_method(void, TYPE(id, SEL, id), view, S("setBackgroundColor:"), color); | |
objc_method(void, TYPE(id, SEL, id), window, S("setRootViewController:"), viewController); | |
objc_method(void, TYPE(id, SEL), window, S("makeKeyAndVisible")); | |
return YES; | |
} |
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 <objc/objc.h> | |
void initializeAppDelegate(); | |
BOOL didFinishLaunching(id self, SEL sel, id application, id launchOptions); |
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 <CoreFoundation/CoreFoundation.h> | |
#import "AppDelegate.h" | |
#import "objc-insanity.h" | |
void *objc_autoreleasePoolPush(void); | |
void objc_autoreleasePoolPop(void *pool); | |
int UIApplicationMain(int argc, char** argv, id principalClassName, id delegateClassName); | |
int main(int argc, char** argv) { | |
void* pool = objc_autoreleasePoolPush(); | |
initializeAppDelegate(); | |
int retval = UIApplicationMain(argc, argv, nil, (id)CFSTR("AppDelegate")); | |
objc_autoreleasePoolPop(pool); | |
return retval; | |
} |
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 <objc/message.h> | |
#define TYPE(...) __VA_ARGS__ | |
#define S(n) sel_getUid(n) | |
#define objc_method(return_type, type, ...) ((return_type(*)(type))objc_msgSend)(__VA_ARGS__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment