Creates a user defaults object initialized with the defaults for the specified database name.


init?(suiteName suitename: String?)



The domain identifier of the search list.

If you pass nil to this parameter, the system uses the default search list that the standard class method uses. Because a suite manages the defaults of a specified app group, a suite name must be distinct from your app’s main bundle identifier. The globalDomain is also an invalid suite name, because it isn't writeable by apps.


You can use this method when developing an app suite, to share preferences or other data among the apps, or when developing an app extension, to share preferences or other data between the extension and its containing app.

The argument and registration domains are shared between all instances of UserDefaults.

The suiteName parameter matches the domain parameter of the corresponding CFPreferences APIs (except when translating between Foundation and Core Foundation constants). Listing 1 shows two equivalent statements. For more details, see Preferences Utilities.

Listing 1

Equivalent statements using NSUserDefaults and CFPreferences APIs

let userDefaultsValue = UserDefaults(suiteName: "someDomain")?.object(forKey: "someKey")
let preferencesValue = CFPreferencesCopyAppValue("someKey" as CFString, "someDomain" as CFString)
// userDefaultsValue and preferencesValue are equal

On macOS, specifying another app’s bundle identifier will get you that app’s preferences search list, unless prevented by the App Sandbox.

See Also

Creating User Defaults Objects


Creates a user defaults object initialized with the defaults for the app and current user.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software