Exception: addEvent is not a recognised Objective C method

1.1k Views Asked by At

I'm porting swift class to ReactNative.

my CalendarManager.Swift class

CalendarManager.Swift

 import Foundation;


import UIKit;
// CalendarManager.swift

@objc(CalendarManager)
class CalendarManager: NSObject {

  @objc
  func addEvent(_name: String, location: String, date: NSNumber) -> Void {
    // Date is ready to use!

      NSLog("%@ %@ %S", _name, location, date);
   // self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
  }

}

my objective C class

CalendarManager.m

#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(CalendarManager , NSObject)

RCT_EXTERN_METHOD(addEvent: (NSString *)name location:(NSString *)location date:(NSNumber *)date)

@end

SwiftBridge-header

#import <React/RCTBridgeModule.h>

Please let me know how to reduce that following error.

enter image description here

1

There are 1 best solutions below

0
On

Try to Provide a method description for Objective-C.

Your fn:

@objc
  func addEvent(_name: String, location: String, date: NSNumber)...

Try changing it to:

@objc(addEvent:::)
  func addEvent(name: String, location: String, date: NSNumber)...

where, ':' represents a parameter, since the function is receiving 3, so there would be 3 colons or you can pass variable names as well, though it won't matter.