一,代码。

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. 解决:HTML中多文本域(textarea)回车后数据存入数据库,EL表达式取出异常。

    问题描述: 当多文本域(textarea)回车后数据存入数据库. EL表达式取出异常,值换行倒置页面报错. 问题解决: 存值脚本代码,提交前转换\n为<br/>. <script t ...

  2. ASP.NET MVC在线预览Excel、Word、TXT、PDF文件

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste ...

  3. 倍数提高工作效率的 Android Studio 奇技

    来源:JeremyHe 链接:http://zlv.me/posts/2015/07/13/14_android-studio-tips/ 这是从Philippe Breault的系列文章<An ...

  4. Visual Studio统计代码行数

    按[Ctrl+Shift+F]弹出查找窗口(不统计以#号开头.以/开头的代码和空行) 1.输入  :b*[^:b#/]+.*$ 2.选择使用正则表达式 3.查找文件类型,*.cs多种类型用分号(;)隔 ...

  5. 【Java每日一题】20161012

    package Oct2016; public class Ques1012 { public static void main(String[] args) { System.out.println ...

  6. WebView的使用及添加进度条

    实现的效果比较简单类似于微信打开网页,头部有个进度条显示加载进度 下载地址:http://download.csdn.net/detail/qq_29774291/9666941 1.在安卓端加载一个 ...

  7. 解决ambiguous symbol命名空间中类名、变量名冲突的问题

    最近在将一个复杂的工程集成到现有的项目中.编译时发现,有的变量名冲突了,提示就是xxxx ambiguous symbol,并且在编译输出时,指明了两个文件当中特定的变量名或者类名相同.出现这个编译错 ...

  8. Scalaz(32)- Free :lift - Monad生产线

    在前面的讨论里我们提到自由数据结构就是产生某种类型的最简化结构,比如:free monoid, free monad, free category等等.我们也证明了List[A]是个free mono ...

  9. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...

  10. C++/C互相调用

    C调用C++: 在C++程序中使用extern "C"{}来明确要求C++编译器不要对被调用的C++函数进行换名处理, 当然,这会导致函数无法重载 C++调用C: 在C++程序中使 ...