Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from __future__ import annotations
from typing import Optional
from kivy import platform
class SingletonMeta(type):
_instance: Optional[Singleton] = None
def __call__(self) -> Singleton:
if self._instance is None:
self._instance = super().__call__()
return self._instance
class Singleton(metaclass=SingletonMeta):
def __init__(self):
if platform == "ios":
from pyobjus import autoclass
self.banner_ad = autoclass("adSwitch").alloc().init()
self.interstitial_ad = autoclass("adInterstitial").alloc().init()
def show_interstitial(self):
print("show_interstitial python")
if platform == "ios":
def show_banner(self):
print("show_banner python")
if platform == "ios":
def hide_banner(self):
print("hide_ads python")
if platform == "ios":
if __name__ == "__main__":
s1 = Singleton()
s2 = Singleton()
if id(s1) == id(s2):
print("Singleton works, both variables contain the same instance.")
print("Singleton failed, variables contain different instances.")
Copy link

dbrova15 commented Nov 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment