To read and save NSUserDefaults from the same set, you need the following:
- In the main application, select your project in the project navigator.
- Select the goal of your main application and go to the features tab.
- Turn on application groups (they will interact with the developer portal, since it generates a set of permissions, the corresponding application identifier, etc.).
- Create a new container. According to the help, it should start with "group.", So give it a name, for example, "group.myapp.test".
- Select the "Expand Today" goal and repeat this process of including application groups. Do not create a new one, instead select this newly created group to indicate that the Today extension is a member of the group.
Write to your NSUserDefaults:
// In this example Iยดm setting FirstLaunch value to true NSUserDefaults(suiteName: "group.myapp.test")!.setBool(true, forKey: "FirstLaunch")
Read from NSUserDefaults:
// Getting the value from FirstLaunch let firstLaunch = NSUserDefaults(suiteName: "group.myapp.test")!.boolForKey("FirstLaunch") if !firstLaunch { ... }
Swift 4.x:
Record:
UserDefaults(suiteName: "group.myapp.test")!.set(true, forKey: "FirstLaunch")
reading:
UserDefaults(suiteName: "group.myapp.test")!.bool(forKey: "FirstLaunch")
Rashwan l
source share