标签:
使用:
1.倒入 #import "HLPlistData.h"
/**
方法类型: 1.HLPLGET //获取 2.HLPLSET //添加
*/
2.调用 [HLPlistData HlPlst:(方法类型) PlistName:(创建plist文件的名称) Data:(想要上传的数据[字典类型]) Result:^( NSDictionary *data){
/**
类型为HLPLGET时才会有返回结果,否则填nil
*/
NSLog(@"返回的结果%@",data);
}];
// // HLPlistData.h // plist缓存 // // Created by 黄磊 on 16/4/27. // Copyright © 2016年 黄磊. All rights reserved. // #import <Foundation/Foundation.h> @interface HLPlistData : NSObject typedef NS_OPTIONS(NSInteger, HLClass){ HLPLGET = 0,//获取 HLPLSET = 1//添加 }; //累累plist缓存 +(void)HlPlst:(HLClass)class PlistName:(NSString *)name Data:(NSDictionary *)data Result:(void(^)(NSDictionary *data))result; @end
// // HLPlistData.m // plist缓存 // // Created by 黄磊 on 16/4/27. // Copyright © 2016年 黄磊. All rights reserved. // #import "HLPlistData.h" @implementation HLPlistData +(void)HlPlst:(HLClass)class PlistName:(NSString *)name Data:(NSDictionary *)data Result:(void(^)(NSDictionary *data))result{ NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [pathArray objectAtIndex:0]; NSString *filePatch = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist",name]]; switch (class) { case HLPLGET: data = [NSDictionary dictionaryWithContentsOfFile:filePatch]; result(data); break; case HLPLSET: [data writeToFile:filePatch atomically:YES]; break; } } @end
标签:
原文地址:http://www.cnblogs.com/huanglert/p/5442339.html