ObjCRuntime.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <objc/objc.h>
  3. #include <objc/runtime.h>
  4. #include <objc/message.h>
  5. // simulator and device differ in how they want objc_msgSendXXX to be called:
  6. // device wants objc_msgSendXXX to be casted to proper type (same as selector we want to call)
  7. // while simulator wants to call them directly
  8. #if TARGET_IPHONE_SIMULATOR || TARGET_TVOS_SIMULATOR
  9. #define UNITY_OBJC_SEND_MSG(selectorType, msgSendFunc) msgSendFunc
  10. #else
  11. #define UNITY_OBJC_SEND_MSG(selectorType, msgSendFunc) ((selectorType)msgSendFunc)
  12. #endif
  13. #define UNITY_OBJC_FORWARD_TO_SUPER(self_, super_, selector, selectorType, ...) \
  14. do { \
  15. struct objc_super super = { .receiver = self_, .super_class = super_ }; \
  16. UNITY_OBJC_SEND_MSG(selectorType, objc_msgSendSuper)(&super, selector, __VA_ARGS__); \
  17. } while(0)
  18. #define UNITY_OBJC_CALL_ON_SELF(self_, selector, selectorType, ...) \
  19. do { \
  20. UNITY_OBJC_SEND_MSG(selectorType, objc_msgSend)(self_, selector, __VA_ARGS__); \
  21. } while(0)
  22. // method type encoding for methods we override
  23. // to get this you need to do: method_getTypeEncoding(class_getInstanceMethod(class, sel)) or method_getTypeEncoding(class_getClassMethod(class, sel))
  24. #define UIView_LayerClass_Enc "#8@0:4"
  25. #define UIViewController_supportedInterfaceOrientations_Enc "Q16@0:8"
  26. #define UIViewController_prefersStatusBarHidden_Enc "B16@0:8"
  27. #define UIScreen_maximumFramesPerSecond_Enc "q16@0:8"
  28. #define UIView_safeAreaInsets_Enc "{UIEdgeInsets=dddd}16@0:8"