ios - 删除存储在 nsuserdefault 中的 nsdata

标签 ios nsuserdefaults nsdata

我将图像数据 (NSData) 作为数组保存在 NSUserDefault 中,同时重新启动应用程序并尝试从存储在 NSUserDefault 中的数组中删除图像数据,数据没有删除..

最佳答案

假设您已经使用关键“imagedata”存储图像数据,如下代码行

[[NSUserDefaults standardUserDefaults] setObject:imageData forKey :@"imageData"];

如何删除关键 imageData 存储的数据如下代码行:

 NSMutableArray *arr= [[NSUserDefaults standardUserDefaults] objectForKey:@"imageData"]]mutableCopy];// If array is not mutable then make it mutable then remove
[arr removeObjectAtIndex:index];
[[NSUserDefaults standardUserDefaults] setObject:arr forKey :@"imageData"];

检查您的代码后更新我的答案 更新

尝试数组的方法removeObjectIdenticalTo

关于ios - 删除存储在 nsuserdefault 中的 nsdata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36498568/

相关文章:

ios - 为什么我不能在 UIPageViewController 中设置 View Controller ?

ios - 如何处理 NSData 并返回 UIImage (Swift)

swift:向数据添加字节的正确方法

ios - 应用程序会丢失无线安装的 NSUserDefault 数据吗?

ios - NSData dataWithContentsOfURL 泄漏和 datawithContentsOfURL :options:error reports the URL is nil?

ios - SwiftData(SQLite 包装器)在 Swift 3.0 中损坏

ios - 使用 UIViewControler 和 UITableView 在 UITabBarController 中切换选项卡后 UIRefreshControl 卡住了

ios - iOS 应用程序中 LaTex、MathML 和 XHTMLMathML 之间的权衡?

swift - 如何在Swift中美化缓存 "pattern"?

ios - 将 NSArray 保存到 NSUserDefaults 不起作用