【代码笔记】iOS-缓存路径操作类
一,代码。
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-缓存路径操作类的更多相关文章
- 【代码笔记】Java基础:类的继承(构造器)
在Java中,创建对象的格式为: 类名 对象名 = new 类名(): 如: 1 JFrame jf = new JFrame(); 一个对象被创建出来时,经常要先做一些事这个对象才能正常使用,也可以 ...
- ORB-SLAM 代码笔记(五)Frame类
Frame类的成员变量主要包含从摄像头获取的图像的 1. 特征点信息(关键点+描述字) 2. 尺寸不变特征所用金字塔信息,这些都定义在ORBextractor对象中 3. 词袋模型参数,用于跟踪失败情 ...
- C# FTP操作类的代码
如下代码是关于C# FTP操作类的代码.using System;using System.Collections.Generic;using System.Text;using System.Net ...
- 3.NetDh框架之缓存操作类和二次开发模式简单设计(附源码和示例代码)
前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...
- 简单的php数据库操作类代码(增,删,改,查)
这几天准备重新学习,梳理一下知识体系,同时按照功能模块划分做一些东西.所以.mysql的操作成为第一个要点.我写了一个简单的mysql操作类,实现数据的简单的增删改查功能. 数据库操纵基本流程为: 1 ...
- JAVA文件操作类和文件夹的操作代码示例
JAVA文件操作类和文件夹的操作代码实例,包括读取文本文件内容, 新建目录,多级目录创建,新建文件,有编码方式的文件创建, 删除文件,删除文件夹,删除指定文件夹下所有文件, 复制单个文件,复制整个文件 ...
- 封装php redis缓存操作类
封装php redis缓存操作类,集成了连接redis并判断连接是否成功,redis数据库选择,检测redis键是否存在,获取值,写入值,设置生存时间和删除清空操作. php redis类代码: &l ...
- File IO(NIO.2):路径类 和 路径操作
路径类 Java SE 7版本中引入的Path类是java.nio.file包的主要入口点之一.如果您的应用程序使用文件I / O,您将需要了解此类的强大功能. 版本注意:如果您有使用java.io. ...
- 2.NetDh框架之简单高效的日志操作类(附源码和示例代码)
前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...
随机推荐
- C# 日志的配置流程
1. 下载log4net.dll文件 http://download.csdn.net/detail/abc456456456456/7653857 2. 项目中引用此dll 3. appconfig ...
- ASP.NET MVC系列:开始
创建Asp.Net MVC项目 从visual studio主界面开始菜单中点击“新建项目”
- HoverTree开发日志之验证码
HoverTree是一个ASP.NET的开源CMS,目前包含文章系统,图库和留言板功能.代码完全开放,文章内容页生成了静态的HTM页面,留言板提供留言审核功能,文章可以发布HTML源代码,图片上传同时 ...
- 下一代USB接口将支持双向拔插,于明年亮相
近日,USB接口标准制定组织表示新一代USB接口将于明年年中亮相,而其名称目前被暂定为了USB Type-C.该组织表示USB Type-C标准将允许制造商采用更纤薄的接口设计,在实用性大大提高的同时 ...
- SQL更改表字段为自增标识
下面是SQL语句: --删除主键约束 ) select @Constraint_Name = Name from dbo.sysobjects where Xtype = 'PK' and Paren ...
- Kosaraju算法---强联通分量
1.基础知识 所需结构:原图.反向图(若在原图中存在vi到vj有向边,在反向图中就变为vj到vi的有向边).标记数组(标记是否遍历过).一个栈(或记录顶点离开时间的数组). 算法描叙: :对 ...
- PowerDesigner中Table视图怎样同时显示Code和Name
1.创建一个简单table视图步骤: 1)打开软件,创建model,选择Physical Data
- linux命令笔记
3步实现ssh login不用密码: 1 ssh-keygen (Create public and private keys) 2 ssh-copy-id -i ~/.ssh/id_rsa.pub ...
- FAILED BINDER TRANSACTION
最近开发Widget,要在Widget上显示图片,出现了FAILED BINDER TRANSACTION错误,后来才发现是因为图片太大了.Widget使用的是RemoteViews,而Intent传 ...
- Yii2框架打包成Phar包报错的经历
以yii2为例 打包文件过程比较简单,但打包好以后简单测试yii命令,一直报错: PHP Fatal error: Uncaught yii\base\InvalidParamException: T ...