zoukankan      html  css  js  c++  java
  • NSUserdefaults清除存储内容

    有两种方式

    方式一:找到所有的key,然后删除对象

    1. /** 
    2.  *  清除所有的存储本地的数据 
    3.  */  
    4. - (void)clearAllUserDefaultsData  
    5. {  
    6.     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  
    7.       
    8.     NSDictionary *dic = [userDefaults dictionaryRepresentation];  
    9.     for (id  key in dic) {  
    10.         [userDefaults removeObjectForKey:key];  
    11.     }  
    12.     [userDefaults synchronize];  
    13. }  

    方式二:清除持久域

    1. /** 
    2.  *  清除所有的存储本地的数据 
    3.  */  
    4. - (void)clearAllUserDefaultsData  
    5. {  
    6.       
    7.     NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];  
    8.     [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];  
    9.       
    10.       
    11. }  
  • 相关阅读:
    git
    ComfortColor.xcs
    使用Jackson时转换JSON时,日期格式设置
    json和jsonp
    powerdesigner 将表中name列值复制到comment列 (保留原有comment)
    下滑线驼峰互转
    Tomcat
    git stash
    gitignore
    例题:大图轮播
  • 原文地址:https://www.cnblogs.com/shycie/p/7605416.html
Copyright © 2011-2022 走看看