NSUserDefaults 已经有键值对了吗? -swift
NSUserDefaults already has key and value pairs? -swift
我在我的应用程序中使用 NSUserDefaults,当我启动该应用程序时,NSUserDefaults 似乎已经具有默认值。当我在我的应用程序开头将 NSUserDefaults 打印为字典时,它具有默认值。这是将其打印为字典的样子:
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh, AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh,
AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh,
AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
是的,对于语言有一些预设值。正如您所指出的,您粘贴的项目是语言。甚至 "zh-Hans" 等引号中的项目也指的是语言,在这种情况下是中文的不同方言。
在 gnustep.org 上注意到 "The NSLanguages default value is used to set up the constants for localization."
我在我的应用程序中使用 NSUserDefaults,当我启动该应用程序时,NSUserDefaults 似乎已经具有默认值。当我在我的应用程序开头将 NSUserDefaults 打印为字典时,它具有默认值。这是将其打印为字典的样子:
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh, AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh,
AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
[MSVLoggingMasterSwitchEnabledKey: 0, NSLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
), AppleITunesStoreItemKinds: (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), AppleKeyboardsExpanded: 1, NSInterfaceStyle: macintosh,
AppleKeyboards: (
"en_US@hw=US;sw=QWERTY",
"emoji@sw=Emoji",
"en_US@hw=US;sw=QWERTY"
), AppleLocale: en_US, AppleLanguages: (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
nl,
it,
es,
"es-MX",
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
"en-AU",
ca,
hu,
vi,
hi
)]
是的,对于语言有一些预设值。正如您所指出的,您粘贴的项目是语言。甚至 "zh-Hans" 等引号中的项目也指的是语言,在这种情况下是中文的不同方言。
在 gnustep.org 上注意到 "The NSLanguages default value is used to set up the constants for localization."