chitranjan deo chitranjan deo - 11 months ago 57
iOS Question

How to share a variable value between two extensions in IOS using swift without using Coredata

Lets say, I have two extensions in a project. And I want to set a variable in one extension and read the updated value of that variable from another extension. I don't want to use Coredata.

Currently, I am using Common cocoa touch framework and imported that framework in both the extensions. I have defined getter and setter for one of the variable in the class defined in common framework. But, the changed value by one extension is not showing to another extension.

Any idea, why its not updating or anyother approach please.


Use NSUserDefaults:

To set value:

NSUserDefaults.standardUserDefaults().setObject(someValue, forKey: "myName")

To get value:(in another extension)