【代码笔记】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,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...
随机推荐
- StringExtensions
public static string MakeSafeSql(this string s) { string t = s; t = t.Replace("'", "' ...
- 浅谈 block(1) – clang 改写后的 block 结构
这几天为了巩固知识,从 iOS 的各个知识点开始学习,希望自己对每一个知识理解的更加深入的了解.这次来分享一下 block 的学习笔记. block 简介 block 被当做扩展特性而被加入 GCC ...
- Android SDK Android NDK Android Studio 官方下载地址
2016.12 Android Studio Windows Includes Android SDK https://dl.google.com/dl/android/studio/install/ ...
- 能不能用javascript实现素数求和问题呢?
先自己试试吧 好吧,下面这段代码用了别人所说的最笨的方法,身为小白的我只能呵呵.待会再尝试用其他算法. <!DOCTYPE html> <html lang="en&quo ...
- ASP.NET MVC 使用Jquery Uploadify 在非IE浏览器下Http Error的解决方案
解决Uploadify上传控件在非IE浏览器中不工作,需要做如下2步修改: 1.Global.asax文件中,实现Application_BeginRequest函数: void Applicatio ...
- IIS MIME类型大全
文件如果下载不了,可能是iis中的MIME设置问题.格式前面为后辍名,后面为对应的MIME型(例如:rar application/x-rar-compressed 表示.RAR对应的是applica ...
- wcf和web service的区别
1.WebService:严格来说是行业标准,不是技术,使用XML扩展标记语言来表示数据(这个是夸语言和平台的关键).微软的Web服务实现称为ASP.NET Web Service.它使用Soap简单 ...
- How Will Java Technology Change My Life?
How Will Java Technology Change My Life? We can't promise you fame, fortune, or even a job if you le ...
- 框架Maven笔记系列 一 基础
主题:SpringMVC 学习资料参考网址: 1.http://www.icoolxue.com 2.http://maven.apache.org/ 1.Maven解决了什么问题? Maven基于项 ...
- Guava学习笔记:Guava新增集合类型-Multimap
在日常的开发工作中,我们有的时候需要构造像Map<K, List<V>>或者Map<K, Set<V>>这样比较复杂的集合类型的数据结构,以便做相应的业 ...