Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React-native bridging with Swift singleton custom class

$
0
0

Today, I try to use my custom Swift class implementing Singleton pattern in my Javascript code. I already created native modules but today I've got this error : "Fatal error: Use of unimplemented initializer 'init()' for class"

I guess it's because the Singleton pattern but I can't understand my mistake ...

Here's my code:

AnalyticsTracker.swiftimport Foundationimport Tracker@objc(AnalyticsTracker)class AnalyticsTracker: NSObject {  static let shared = AnalyticsTracker(tracker: ATInternet.sharedInstance.defaultTracker)  // MARK: -  let tracker: Tracker  // Initialization  private init(tracker: Tracker) {    self.tracker = tracker  }  @objc  func viewScreen(screen: String) {    self.tracker.screens.add(screen).sendView()  }  @objc  func sendTouch(clickName: String, chapter1: String, chapter2: String, chapter3: String, level2: Int) {    let gesture = self.tracker.gestures.add(clickName, chapter1: chapter1, chapter2: chapter2, chapter3:chapter3)    gesture.level2 = level2    gesture.sendTouch()  }}

And the module to export my class to my react-native application :

AnalyticsTracker.m#import <Foundation/Foundation.h>#import <React/RCTBridgeModule.h>@interface RCT_EXTERN_MODULE(AnalyticsTracker, NSObject)RCT_EXTERN_METHOD(                  sendTouch:                  (NSString*)clickName                  (NSString*)chapter1                  (NSString*)chapter2                  (NSString*)chapter3                  (int)level2)@end

The error disappear when I remove the export module. I really don't understand what the error mean ...

If someone have an idea it would be really appreciated :)


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>