Initializer

init(suiteName:)

Creates a user defaults object initialized with the defaults for the specified database name. ユーザdefaultsオブジェクトを作成します、指定されたデータベース名に対するdefaultsで初期化されます。

Declaration 宣言

init?(suiteName suitename: String?)

Parameters パラメータ

suitename

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. あなたがnilをこのパラメータに渡すならば、システムはdefault検索リストを使います、それはstandardクラスメソッドが使うものです。あるスイートがある指定されたアプリグループのdefaultsを管理することから、スイート名はあなたのアプリのもつメインバンドル識別子と別個のものでなければなりません。globalDomainはまた無効なスイート名です、なぜならそれはアプリによって書き込み可能でないからです。

Discussion 議論

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. 引数と登録ドメインは、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. suiteNameパラメータは、対応するCFPreferences APIのドメインパラメータと一致します(FoundationとCore Foundation定数の間で転換している時を除いて)。コード出力 1 は、2つの同等の文を示します。さらなる詳細として、Preferences Utilitiesを見てください。

Listing 1 Equivalent statements using NSUserDefaults and CFPreferences APIs コード出力 1 NSUserDefaults と CFPreferences APIを使っている同等の文

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. macOSでは、別のアプリのもつバンドル識別子を指定することは、あなたにそのアプリのもつ環境設定それらの検索リストを持ってきます、App Sandboxによって防止されない限りは。

See Also 参照

Creating User Defaults Objects ユーザdefaultsオブジェクトを作成する