1

I am integrating React Native to an existing iOS/Android Project. I am trying to make a native module to help with navigating to iOS screens from React Native screens. I was able to create my Android Native Module for navigation to call Android Activities from React Native.

When writing my Navigation Native Module for iOS, Xcode keeps highlighting my method with a "Semicolon before method body is ignored" error for all my RCT_EXPORT_METHOD() methods.

I am using Xcode 9.2, React Native 0.59.3.

https://facebook.github.io/react-native/docs/native-modules-ios#docsNav

I have been following the documentation from above and I cannot figure out why Xcode is not recognizing the syntax. I've also tried running code in Xcode 9.4 and get the same "Semicolon before method body is ignored" syntax error.

NavigationModule.h

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>

@interface NavigationModule : NSObject <RCTBridgeModule>

@end

NavigationModule.m

#import "NavigationModule.h"

@implementation NavigationModule

RCT_EXPORT_MODULE(NavigationModule);

RCT_EXPORT_METHOD(onOptionAboutSelected:(NSString *)title)
{
    //TODO
}

RCT_EXPORT_METHOD(onOptionLockSelected)
{
    //TODO
}


@end

Any help would be appreciated.

Maddie R.
  • 9
  • 3

2 Answers2

0

This is triggered by the -Wsemicolon-before-method-body compiler flag on code like

- (void)foo;
{
// Method body
}

(Note the semicolon after foo.)

The "correct" fix is simply to remove the semicolon:

- (void)foo
{
// Method body
}

However, if you don't want or aren't able to change the code in question, you can disable the warning:

  • Set "Semicolon Before Method Body" to NO in your build settings.

or (if you have something like -Weverything enabled)

  • Add -Wno-semicolon-before-method-body to "Other Warning Flags".
Wevah
  • 28,182
  • 7
  • 83
  • 72
-1

Found solution: Needed to change XCode settings for the project.

Project -> Select Target -> Build Settings -> Set "Treat warnings as error" to "No".

Code should build.

Maddie R.
  • 9
  • 3