问题描述
var sharedPreference : UserDefaults = UserDefaults.init(suiteName: "userKeyValue")!
我正在这样创建UserDefault实例,很可能是它在设备中使用名称userKeyValue
创建一个空格,并在其中保留所有键值对.
I am creating UserDefault instance like this and most probably it is creating a space in device with name userKeyValue
and keep all key value pairs in that.
现在我想将内容迁移到其他UserDefault
实例
Now I want to migrate the content to different UserDefault
instance
var oldSharedPreference : UserDefaults? = UserDefaults(suiteName: "userKeyValue")
if (oldSharedPreference != nil) {
print("Previous data found")
for (key, value) in oldSharedPreference!.dictionaryRepresentation() {
sharedPreference.set(value, forKey: key)
}
sharedPreference.synchronize()
oldSharedPreference!.removeSuite(named: "userKeyValue")
oldSharedPreference!.synchronize()
}
我一次又一次地多次安装该应用程序,但是每次获取日志Previous data found
时.我不知道我是否以正确的方式进行操作.
I installed the app many times in one after another but every time I am getting the log Previous data found
. I dont know if i am doing it in correct way or not.
我只希望userKeyValue
的UserDefaults
实例不存在,一旦运行这段代码,但这不会发生.
I just want that existence of UserDefaults
instance of userKeyValue
should no longer exists once this piece of code runs but this is not happening.
更新::创建实例时,我正在UserDefault中获取此内容
UPDATE:: I am getting this content in UserDefault when its instance is created
["AKLastCheckInSuccessDate": 2019-06-03 09:06:11 +0000, "NSLanguages": <__NSArrayI 0x2820289c0>(
en-IN,
en
)
, "com.apple.content-rating.TVShowRating": 1000, "com.apple.content-rating.ExplicitBooksAllowed": 1, "AppleLanguagesDidMigrate": 16E227, "INNextHearbeatDate": 581574895.850746, "AppleLocale": en_IN, "NSInterfaceStyle": macintosh, "AKLastCheckInAttemptDate": 2019-06-09 20:42:49 +0000, "AddingEmojiKeybordHandled": 1, "com.apple.content-rating.MovieRating": 1000, "AKLastIDMSEnvironment": 0, "AKLastEmailListRequestDateKey": 2019-06-03 09:04:39 +0000, "AppleLanguages": <__NSCFArray 0x283579f80>(
en-IN
)
, "com.apple.content-rating.AppRating": 1000, "com.apple.content-rating.ExplicitMusicPodcastsAllowed": 0, "PKKeychainVersionKey": 4, "AppleKeyboards": <__NSCFArray 0x28357a080>(
en_IN,
emoji
)
, "AppleITunesStoreItemKinds": <__NSCFArray 0x281531080>(
itunes-u,
movie,
ringtone,
album,
software-update,
booklet,
tone,
music-video,
song,
podcast,
software,
podcast-episode,
wemix,
eBook,
artist,
mix,
document
)
, "INNextFreshmintRefreshDateKey": 581904664.355094, "ApplePasscodeKeyboards": <__NSCFArray 0x28357a0c0>(
en_IN@sw=QWERTY;hw=Automatic,
emoji@sw=Emoji
)
, "AppleKeyboardsExpanded": 1]
推荐答案
您是否尝试删除整个域?
Did you try to remove the whole domain?
UserDefaults.standard.removePersistentDomain(forName: "userKeyValue")
UserDefaults.standard.synchronize()
从Apple 文档
这篇关于在UserDefault中删除套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!