一,代码。

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSMutableDictionary *cachedData;
} @property (strong, nonatomic) UIWindow *window; @end

AppDelegate.m

#import "AppDelegate.h"
#import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch. RootViewController *rootVC=[[RootViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:rootVC];
self.window.rootViewController=nav; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - 缓存
- (void)initCachedCapacity;
{
if (!cachedData) {
cachedData = [[NSMutableDictionary alloc] init];
}
[cachedData removeAllObjects];
[self readDataFromFile:@"cachedData" toTheData:cachedData];
NSLog(@"initCachedCapacity");
}
- (void)saveCachedCapacity
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[self saveDataToFile:cachedData theFileName:@"cachedData"];
[userDefaults synchronize];
NSLog(@"saveCachedCapacity"); } #pragma mark - 缓存路径操作类
// 返回文件路径
- (NSString *)dataFilePath:(NSString *)fileName { NSString *homeDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
NSString *filePhyPath=[homeDirectory stringByAppendingPathComponent:fileName]; return filePhyPath;
}
// 存储数据到文件
- (void)saveDataToFile:(id)paramData theFileName:(NSString *)paramName{ NSString *savePath=[self dataFilePath:paramName]; if ([paramData isKindOfClass:[NSMutableDictionary class]]) { [paramData writeToFile: savePath atomically: YES]; return;
} if ([paramData isKindOfClass:[NSMutableArray class]]) { [paramData writeToFile: savePath atomically: YES]; } }
// 读取数据从文件
- (void)readDataFromFile:(NSString *)fileName toTheData:(id) paramData{ if ([paramData isKindOfClass:[NSMutableDictionary class]]) { NSMutableDictionary* tmp = [[NSMutableDictionary alloc] initWithContentsOfFile:[self dataFilePath:fileName]];
if (tmp&& tmp.count>0) {
[paramData addEntriesFromDictionary:tmp];
}
return;
}
if ([paramData isKindOfClass:[NSMutableArray class]]) { NSMutableArray *tmp=[[NSMutableArray alloc] initWithContentsOfFile:[self dataFilePath:fileName]]; if (tmp&& tmp.count>0) {
[paramData addObjectsFromArray:tmp]; }
return; }
} - (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} @end
 
 

【代码笔记】iOS-缓存路径操作类的更多相关文章

  1. 【代码笔记】Java基础:类的继承(构造器)

    在Java中,创建对象的格式为: 类名 对象名 = new 类名(): 如: 1 JFrame jf = new JFrame(); 一个对象被创建出来时,经常要先做一些事这个对象才能正常使用,也可以 ...

  2. ORB-SLAM 代码笔记(五)Frame类

    Frame类的成员变量主要包含从摄像头获取的图像的 1. 特征点信息(关键点+描述字) 2. 尺寸不变特征所用金字塔信息,这些都定义在ORBextractor对象中 3. 词袋模型参数,用于跟踪失败情 ...

  3. C# FTP操作类的代码

    如下代码是关于C# FTP操作类的代码.using System;using System.Collections.Generic;using System.Text;using System.Net ...

  4. 3.NetDh框架之缓存操作类和二次开发模式简单设计(附源码和示例代码)

    前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...

  5. 简单的php数据库操作类代码(增,删,改,查)

    这几天准备重新学习,梳理一下知识体系,同时按照功能模块划分做一些东西.所以.mysql的操作成为第一个要点.我写了一个简单的mysql操作类,实现数据的简单的增删改查功能. 数据库操纵基本流程为: 1 ...

  6. JAVA文件操作类和文件夹的操作代码示例

    JAVA文件操作类和文件夹的操作代码实例,包括读取文本文件内容, 新建目录,多级目录创建,新建文件,有编码方式的文件创建, 删除文件,删除文件夹,删除指定文件夹下所有文件, 复制单个文件,复制整个文件 ...

  7. 封装php redis缓存操作类

    封装php redis缓存操作类,集成了连接redis并判断连接是否成功,redis数据库选择,检测redis键是否存在,获取值,写入值,设置生存时间和删除清空操作. php redis类代码: &l ...

  8. File IO(NIO.2):路径类 和 路径操作

    路径类 Java SE 7版本中引入的Path类是java.nio.file包的主要入口点之一.如果您的应用程序使用文件I / O,您将需要了解此类的强大功能. 版本注意:如果您有使用java.io. ...

  9. 2.NetDh框架之简单高效的日志操作类(附源码和示例代码)

    前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...

随机推荐

  1. UI自动化测试框架(项目实战)python、Selenium(日志、邮件、pageobject)

    其实百度UI自动化测试框架,会出来很多相关的信息,不过就没有找到纯项目的,无法拿来使用的:所以我最近就写了一个简单,不过可以拿来在真正项目中可以使用的测试框架. 项目的地址:https://githu ...

  2. 前端模块化开发之seaJs

    了解后端语言的童鞋一定听过模块化开发的概念,比如java.python等后端语言都有自己的模块化特性,然而和后端语言相比,javascript还尚未实现模块化的功能,虽然之后的更高版本可能引入模块化开 ...

  3. Git undo 操作

    相比传统的版本管理工具,git 的 undo 操作也不是很简单明了,本文尝试总结常用的 undo 操作. 重新提交 应该避免考虑不周全的提交,但这太难了.因此Git 专门提供了一个命令来弥补粗心的提交 ...

  4. 遗传算法的简单应用-巡回旅行商(TSP)问题的求解

    上篇我们用遗传算法求解了方程,其中用到的编码方式是二进制的编码,实现起来相对简单很多, 就连交配和变异等操作也是比较简单,但是对于TSP问题,就稍微复杂一点,需要有一定的策略, 才能较好的实现. 这次 ...

  5. ADB am 命令详细参数

    usage: am [subcommand] [options] usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <F ...

  6. 代码实现SQL Server动态行转列,不用存储过程

    分两步查询,第一步查询出动态列,第二步使用PIVOT函数. 代码: List<DataTable> dataTableList = new List<DataTable>(); ...

  7. 在Linux(Ubuntu)下搭建ASP.NET Core环境并运行 继续跨平台

    最新教程:http://www.cnblogs.com/linezero/p/aspnetcoreubuntu.html 无需安装mono,在Linux(Ubuntu)下搭建ASP.NET Core环 ...

  8. ASP.NET MVC ValueProvider小结

    在Model绑定中,Model的数据来源有很多种,在MVC里面则定义了一套ValueProvider的组件来处理Model数据来源多样性的问题,ValueProvider整个结构类似于字典(Dictr ...

  9. Adb connection Error:远程主机强迫关闭了一个现有的连接

    在用手机调试程序时,有时会出现“Adb connection Error:远程主机强迫关闭了一个现有的连接”的错误. 出现这种错误时,可以按照以下步骤解决: (1)运行cmd.exe,并将目录CD到\ ...

  10. Global和Globals

    $a= '1234'; $a = 'abc'; $GLOBAS['b']='123'; function showVar(){ echo $a;//什么也输不出来 echo $b;//123(全局变量 ...