ocHeader static method

String ocHeader(
  1. Module module,
  2. UniAPIOptions options
)

Implementation

static String ocHeader(Module module, UniAPIOptions options) {
  registerCustomType('id');
  registerCustomType('UniCompleted');

  return CodeTemplate(children: [
    CommentUniAPI(),
    EmptyLine(),
    OCImport(fullImportName: 'Foundation/Foundation.h'),
    EmptyLine(),
    OneLine(body: 'NS_ASSUME_NONNULL_BEGIN'),
    OCForwardDeclaration(
        className: 'FlutterBinaryMessenger', isProtocol: true),
    OCCustomNestedImports(module.inputFile, options,
        methods: module.methods, isForwardDeclaration: true),
    OneLine(
        body: 'typedef void (^UniCompleted)(id result); // 这里result可能是nil'),
    EmptyLine(),
    Comment(comments: [
      uniFlutterModuleDesc,
      'Before using the code generated based on the "UniFlutterModule" template, you need to call the setup method to initialize it.',
      ...module.codeComments
    ]),
    OCClassDeclaration(
        className: module.name,
        parentClass: 'NSObject',
        isInterface: true,
        classMethods: [
          Method(name: 'setup', parameters: [
            Variable(
                AstCustomType('id',
                    generics: [AstCustomType('FlutterBinaryMessenger')]),
                'binaryMessenger')
          ]),
          ...module.methods.map(_transformFlutterModuleMethod)
        ]),
    EmptyLine(),
    OneLine(body: 'NS_ASSUME_NONNULL_END'),
  ]).build();
}