nsuserdefaults

Speed of reading NSUserDefaults vs variables

馋奶兔 提交于 2019-12-06 03:24:55
问题 I have an app and it calls to variables often. And these variables are stored in NSUserDefaults . I'm wondering where NSUserDefaults is storing? And if I call NSUserDefaults directly instead of using variables. Which is faster? variables or NSUserDefaults . Because using variables to store NSUserDefaults will be the cause of using more memory. 回答1: NSUserDefaults persists its data on disk so at some point it must load that data from disk in order to store it in memory. It will need to write

Get NSUserDefaults plist file from device

情到浓时终转凉″ 提交于 2019-12-06 02:26:15
问题 When testing my app on the simulator, I like the ability to edit, or even trash the apps plist file (which contains the NSUserDefaults) from the iPhone Simulator folder. This proves useful when testing (e.g. your app stores a dictionary in there, but you change the model/keys that you use for this data, and therefore need to remove the dictionary stored). Is it possible to access this file on device (for your own app), without jailbreak? Thanks in advance 回答1: The file is in Library

[2015.11.18] Objective-c UIScrollView 页面跳转 线传值

送分小仙女□ 提交于 2019-12-05 23:00:06
[2015.11.18] Objective-c UIScrollView 页面跳转 线传值 NSUserDefault 传值 1. 新知识 A. 为什么要有 UIScrollView : 移动设备的屏幕⼤大⼩小是有限的 , 因此直接展⽰示在⽤用户眼前的内容也相当有限。 但是有的应⽤用 , 它们显⽰示的信息⽐比较多 , 在移动设备的屏幕中容纳不下。此时可使 ⽤用可滚动视图控件 ( UIScrollView ) 来解决 , 顾名思义 , 可滚动视图提供了滚动功 能 , 可显⽰示内容超过移动设备的屏幕的信息。 特点 : 显⽰示⼤大量数据内容。可以垂直滚动 , 也可以⽔水平滚动 ; 缩放功能 ; 分 ⻚页 效果。 B . UIScrollView 格式: (1)// 设置代理 _scrollView.delegate = self; (2)// 设置 scrollView 的偏移量 上下左右都偏移 _scrollView.contentSize = _image.frame.size; // 上下偏移 _scrollView.contentSize = CGSizeMake(0, _image.frame.size.height*2); // 左右偏移 _scrollView.contentSize = CGSizeMake(_image.frame.size.width*1.5, 0)

UserDefaults/KeyedArchiver Frustrations

拜拜、爱过 提交于 2019-12-05 20:57:52
I'm working on a homework app that uses custom Assignment objects for each assignment. I am trying to store an NSMutableArray (casted to an NSArray via initWithArray:) in standardUserDefaults but I'm having trouble with saving and reloading the array. I have a table view from which you can choose to add a new assignment (which loads NewAssignmentViewController). When you save the assignment, it is pushed back to an array in AssigmentsViewController. And then you call it every time you load the UITableView which shows the assignments. Here is the relating code: -(void)saveToUserDefaults:

UIScrollView 和UIPageControl 实现app启动滑动图

拜拜、爱过 提交于 2019-12-05 19:33:52
一、使用NSUserDefaults 判断滑动图有没有出现过,加载滑动图 二、初始化 UIScrollView 和 UIPageControl 为启动滑动图做准备 三、实现UIScrollView的代理方法 四、从屏幕上移除UIScrollView,并保存信息 一、使用 NSUserDefaults 判断滑动图有没有出现过,加载滑动图 NSUserDefaults 简介: NSUserDefaults可以将数据 永久的保存 在手机中,他是一个单例,用起来很方便,所以很适合用于 保存简单的数据 和为 数据做标记。 更多的关于 NSUserDefaults的介绍请看: NSUserDefaults 简介 你可以选择在 AppDelegate.m 中的 didFinishLaunchingWithOptions 方法或者“初始界面”(加载的第一个viewController)的 viewDidLoad 方法中进行判断滑动图是否出现过,写上代码: ? 1 2 3 4 5 6 7 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; //判断滑动图是否出现过,第一次调用时“isScrollViewAppear” 这个key 对应的值是nil,会进入if中 if (![@"YES"

What is the best way to secure user's data saved locally in app and how to test security level?

浪子不回头ぞ 提交于 2019-12-05 17:12:28
After the recent attack on App Store I was thinking is the security meaures implemented in app for the user data security are enough? I know there is no guaranteed way to prevent attacks to your app’s data and logic but still we can frustrate attackers by implementing some kind of security .I am looking for the answers for the following questions. is NSUserDefault is secure? is Keychain Access is secure? Which is the better approach NSUserDefault or Keychain Access or any other recommended? After implementing is there any way I can test by attacking my app ? Store credentials for accessing

iOS 数据持久化

邮差的信 提交于 2019-12-05 15:38:37
iOS 数据持久化 在iOS中,常用的数据持久化操作有四种:plist文件,NSUserdefaults,SQLite3,CoreData. Plist文件:也就是我们常说的属性列表,它是一种明文的轻量级存储方式,存储的格式有很多种,最常规的是XML格式.Plist文件只能用数组或者字典进行读取. 优点: 用来存储少量的数据,响应速度快 其赋值方式简单 缺点: 1.正如优点一样,只能存储少量数据,不能存储大文件数据 2.明文存储,所以其安全性欠缺 NSUserdefaults : 适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名、密码之类的. 其优点与plist文件差不多.但是在使用NSUserdefaults的时候,特别需要注意,因为它不是即时将数据写入文件的,为了防止数据丢失,我们通常需要在后面就手动将其写入文件. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@"name" forKey:@"name"]; [defaults synchronize]; SQLite3 : 是一个轻量级,跨平台的小型数据库,其拥有可移植性高、有着和MySql几乎相同的数据库语句以及无需服务器即可使用的优点: 1.可以存储大量的数据,存储和检索的速度非常快

Saving bool to NSUserDefaults and using it in a if statement using Swift

一世执手 提交于 2019-12-05 15:02:35
问题 I am struggling to figure out how to do an if statement with a bool saved to NSUserDefaults using Swift. I believe I know how to save the bool to NSUserDefaults but a confirmation in that would be greatly appreciated. This is the Objective-C code I am trying to figure out how to use with swift. if(![[NSUserDefaults standardUserDefaults] boolForKey:@"onoroff"]) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"onoroff"]; } this is what I have so far in Swift... if NSUserDefaults

“Expected Declaration” Error in Swift in userDefaults

﹥>﹥吖頭↗ 提交于 2019-12-05 14:27:15
I am trying to save the placeHolderValue in NSUserDefaults, but I am getting an expected declaration error in the third line. let placeHolderValue = 1000 var userDefaults = NSUserDefaults.standardUserDefaults() userDefaults.setValue(placeHolderValue, forKey: "placeholder") userDefaults.synchronize() I've looked everywhere and can't find someone with a similar problem. What am I doing wrong? Thanks! I think I didn't have the code above within a function. Once I placed it inside a function within my class declaration everything ran smoothly: func test() { let placeHolderValue = 1000 var

Save accessory checkmarks on uitableview when users loads view multiple times

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 05:51:48
So I've implemented a UIViewController with a tableview, and basically it loads as a set of "filters" for my uicollectionview. Now, when I click on the checkmarks in my tableview, it "filters" my cells accordingly, but now when I reload the view again I want to display the most recent "checkmarks" I've used, or "filters." I have seen this being implemented with NSUserDefaults, but I have not been able to successfully implement this. If anyone could help me, that will be greatly appreciated. CODE FiltersViewController.m: #import "FiltersViewController.h" @interface FiltersViewController ()