Skip to content

Instantly share code, notes, and snippets.

View brien-crean's full-sized avatar

Brien Crean brien-crean

  • Vancouver, Canada
View GitHub Profile
@harveyconnor
harveyconnor / README.md
Created May 26, 2020 01:13
React Native Swift Module Singleton Pattern with Events Example

React Native Swift Module Singleton Pattern

If you are reading this tutorial please be aware that this is for advanced users that require a singleton pattern in their RN native module and some documentation detail is left out intentionally.

For the sake of this tutorial we will be using TestManager as our class.

Instructions

  1. First of all you need to setup a swift class with a bridging header, in Xcode it will generate this for you upon creating a Swift file.
  2. Create your swift class with the @objc directive.
  3. Create a second class that has a static export of the class in singleton.
  4. Follow the files below for a boilerplat example.
@brennanMKE
brennanMKE / EventEmitter.swift
Last active March 7, 2024 04:04
React Native Event Emitter for RCTEventEmitter in Objective-C and Swift
class EventEmitter
/// Shared Instance.
public static var sharedInstance = EventEmitter()
// ReactNativeEventEmitter is instantiated by React Native with the bridge.
private static var eventEmitter: ReactNativeEventEmitter!
private init() {}