Skip to content

Commit 2930115

Browse files
add safeMainInstance (#668)
1 parent a8dd5ff commit 2930115

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Sources/Mixpanel.swift

+11
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ open class Mixpanel {
231231
}
232232
}
233233

234+
/// Returns the main Mixpanel instance if it has been initialized.
235+
/// - Returns: An optional MixpanelInstance, or nil if not yet initialized.
236+
public class func safeMainInstance() -> MixpanelInstance? {
237+
if let instance = MixpanelManager.sharedInstance.getMainInstance() {
238+
return instance
239+
} else {
240+
MixpanelLogger.warn(message: "WARNING: Mixpanel main instance is NOT initialized. Call Mixpanel.initialize(...) first.")
241+
return nil
242+
}
243+
}
244+
234245
/**
235246
Sets the main instance based on the instance name
236247

0 commit comments

Comments
 (0)