App Group in Today's Extension Swift 3.0

2.2k views Asked by At

I am developing a Today's Extension of an app. I am having some problems regarding App Groups that are used as shared containers between extension and containing app.

  1. Where is the App Group data stored?

  2. How to see what data is stored in the App Group?

1

There are 1 answers

1
svarrall On

Shared Containers is simply a UserDefault dictionary that is shared between Extensions in an App. To store data in the container Init your container using the suiteName UserDefault:

let SharedDefaults = UserDefaults.init(suiteName: "group.com.YOURGROUP")!

TheN to set a value, in this case a String:

SharedDefaults.set("something", forKey: "aKey")

And to retrieve the information (from either the Extension or App) use:

let myString = SharedDefaults.string(forKey: "aKey")

This explains how to to print the contents of the UserDefaults: Easy way to see saved NSUserDefaults?