沙盒根目录:NSString*home = NSHomeDirectory();
利用沙盒根目录拼接”Documents”字符串
NSString *home = NSHomeDirectory();
NSString*documents=[home stringByAppendingPathComponent:@"Documents"];
//创建文件
_filepath=[docPath stringByAppendingPathComponent:@"Date.text"];
//跳转到文件最后面
[filehandle seekToEndOfFile];
//打开个文件
NSFileHandle *filehandle=[NSFileHandle fileHandleForWritingAtPath:_filepath];
//将一个数据写入到文件中
[dateTime writeToFile:_filepath atomically:YES];
//将NSString转换成NSDate类型
NSDate *strDate=[str dataUsingEncoding:NSUTF8StringEncoding];
偏好设置
读取上次保存的设置
NSUserDefaults *defaults = [NSUserDefaultsstandardUserDefaults];
NSString *username = [defaults stringForKey:@"username"];
float textSize = [defaults floatForKey:@"text_size"];
BOOL autoLogin = [defaults boolForKey:@"auto_login"];