ocHeaderCode static method

String ocHeaderCode(
  1. UniAPIOptions options
)

Implementation

static String ocHeaderCode(UniAPIOptions options) {
  return CodeTemplate(children: [
    CommentUniAPI(),
    EmptyLine(),
    OCImport(fullImportName: 'Foundation/Foundation.h'),
    OneLine(body: 'NS_ASSUME_NONNULL_BEGIN'),
    EmptyLine(),
    OneLine(body: '#ifndef UNI_EXPORT'),
    OneLine(body: r'#define UNI_EXPORT(className) \'),
    OneLine(
        body:
            '__attribute__((used, section("__DATA , ${_genSectname(options)}"))) '
            r'\'),
    OneLine(
        body:
            'static char *__uni_export_class_##className##__ = ""#className"";'),
    OneLine(body: '#endif'),
    EmptyLine(),
    OneLine(body: '@interface ${_genObjcClassName(options)} : NSObject'),
    EmptyLine(),
    OneLine(body: '/// 加载导出类'),
    OneLine(body: '+ (void)loadExportClass;'),
    EmptyLine(),
    OneLine(body: '/// 获取协议的遵守者'),
    OneLine(body: '+ (id)get:(NSString *)className;'),
    EmptyLine(),
    OneLine(body: '@end'),
    EmptyLine(),
    OneLine(body: 'NS_ASSUME_NONNULL_END'),
  ]).build();
}