When i add value like reference for UIViewController or string Id to singleton class, then try to access them from share extension i could't get this value again
the share extension create new singleton with null value
How i can make this class and the data inside it shared between main app and extension?
class Gateway:NSObject {
private var id:String? = nil
private weak var delegate:GatewayDelegate!
func set(id:String){
self.id = id
}
func set(gatewayDelegate:GatewayDelegate){
self.delegate = gatewayDelegate
}
func dismiss() {
self.id = nil
self.delegate = nil
}
func append(str:String,_id:String) {
if let id = self.id ,id == _id ,self.delegate != nil {
self.delegate!.gatewayAppend(str: str)
}
}
static let shared = Gateway()
private override init() {}
}
An extension is a completely separate process. It runs in its own sandbox and its own memory. Both your main app and your extension can create an instance of the singleton object, but they will be separate instances. They won't share any data.
To exchange data between your main app and your extension you will need to use an app group with user defaults, the keychain or a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With