Why doesn't NSUserDefaults work between my app & share extension?
<p>I have an iOS app with a share extension. I am trying to share data between them using NSUserDefaults and App Groups but, while I can write into the NSUD object, read it, and <code>synchronize()</code> without error, reading in the extension always results in <code>nil</code>.</p>

<p>I have an app group, the literal string "group.net.foo.bar" for which both the app &amp; extension have configured under Capabilities -> App Groups.  This string is in a constants struct in my app:</p>

<pre><code>struct Forum {
    static let APP_GROUP = "group.net.foo.bar"
    static let AUTH_KEY = "AUTH_KEY"
}
</code></pre>

<p>In the main app I create a UserDefaults object and write to it:</p>

<pre><code>fileprivate lazy var userDefaults: UserDefaults = {
    let defaults = UserDefaults()
    defaults.addSuite(named: Forum.APP_GROUP)
    return defaults
}()

// later
userDefaults.set(apiKey, forKey: Forum.AUTH_KEY)
userDefaults.synchronize()
</code></pre>

<p>Creating a new NSUD object after that <code>synchronize()</code> and retrieving the AUTH_KEY works.  In the extension, I create an NSUD and try to retrieve the value, to no avail:</p>

<pre><code>private lazy var userDefaults: UserDefaults = {
    let defaults = UserDefaults()
    defaults.addSuite(named: Forum.APP_GROUP)
    return defaults
}()

// later
private func getApiKey() -&gt; String? {
    return userDefaults.string(forKey: Forum.AUTH_KEY)
}
// returns nil
</code></pre>

<p>In all of my reading of the Apple docs and depressingly-similar questions here on Stack Overflow I can't divine what I've done incorrectly.</p>

<p>Xcode Version 8.0 (8A218a), also tested with Xcode 8.1 Beta 2.  Same behavior on simulator andy my iPhone 6s running iOS 10.</p>