令牌在预处理器子表达式中不是有效的二元运算

Token is not a valid binary operation in preprocessor subexpression

我正在尝试构建一个反应本机 IOS 应用程序。我在 Android 上完成了所有工作,但现在我想在 IOS 上进行测试。当我尝试在 xcode 中构建项目时。我在 2 行收到以下错误:

第 7 行 AppDelegate.m Token is not a valid binary operator in a preprocessor subexpression

AppDelegate.mToken is nog a valig binary operator in a preprocessor subexpressio

中的第 30 行

我的问题是:如何解决这个错误?

我的内容AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#if def FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

static void InitializeFlipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin:[FlipperKitReactPlugin new]];
  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if def FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"Copaan"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

信息

React-native 版本:0.36.4

反应版本:16.13.1

我尝试过的东西

应该是#ifdef#if defined而不是#if def

#if 也是一个有效的预处理器指令,它测试预处理器表达式是否为非零,因此尝试解析表达式 def FB_SONARKIT_ENABLED 并产生错误。

#ifdef 指令采用单个预处理器标记,在本例中为 FB_SONARKIT_ENABLED,并检查是否有任何定义,是否有关联值。

还有一个 defined 预处理器运算符,可以在 #if 的表达式中使用它来测试正在定义的标记。所以你的表达可以写成:

#ifdef FB_SONARKIT_ENABLED

#if defined(FB_SONARKIT_ENABLED)

#if defined FB_SONARKIT_ENABLED 

第一个在人类编写的代码中可能更常见,defined 运算符往往仅用作较大的预处理器表达式的一部分。

HTH