IOS_UI_本地存储
2015-09-09 17:04
489 查看
#import <UIKit/UIKit.h>
@interface AppDelegate :
UIResponder <UIApplicationDelegate>
@property (strong,
nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
#import "MainViewController.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[_window release];
MainViewController *mainVC = [[MainViewController
alloc]init];
self.window.rootViewController = mainVC;
[mainVC release];
return
YES;
}
#import <UIKit/UIKit.h>
@interface MainViewController :
UIViewController
@end
#import "MainViewController.h"
@interface
MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//1. ios 系统的文件机制SandBox
NSLog(@"%@",NSHomeDirectory());
//user开头的是电脑地址
//一 : 沙盒机制 : 在文件内部可以自由读写,无权访问文件夹外部的内容
// 1. Documents : 用来存储用户相关的内容,比如 : 数据库文件.不要在这个文件夹保存体积大的文件, 如果开启了icloud服务,系统会把这个文件夹的所有内容上传到用户的云盘上
// 2. Caches(缓存) : 缓存文件夹.系统缓存文件和一些第三方的默认缓存地址都是这个文件夹.清除缓存就是清空缓存文件夹.
// 3. Preference : 给开发者配置应用程序使用.
// 4. tmp : 临时文件夹,存储临时文件.清除缓存时一起清除掉
// 二. 简单对象写入本地
NSString *str =
@"大芊芊在吃西瓜";
// 1. 把字符串写入本地要先写一个路径 拼接一个文件路径
//参数一 : 要找的系统文件夹(documents,caches)
//参数二 : 在什么系统区域搜索文件夹
//参数三 : YES绝对路径/user... NO相对路径~/documents... 1.txt 文件路径
//返回值只有一个路径放入数组中
NSString *docPath =[
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES)lastObject];
NSString *strPath = [docPath
stringByAppendingString:@"/1.txt"];
// 2. 将字符串写入本地
// 参数一 : 要写入的路径
// 参数二 : YES保护线程安全 在写入过程是否保证线程安全
// 参数三 : 字符串的编码格式
// 参数四 : 错误
[str writeToFile:strPath
atomically:YES
encoding:NSUTF8StringEncoding
error:nil];
// 运行处地址 查找地址在文件中可以看到结果
//数组写入本地
NSArray *arr =
@[@"a",@"b",@"c"];
//数组拼接本地有两种形式xml或者plist
NSString *arrPath = [docPath
stringByAppendingPathComponent:@"2.xml"];
[arr writeToFile:arrPath
atomically:YES];
}
@interface AppDelegate :
UIResponder <UIApplicationDelegate>
@property (strong,
nonatomic) UIWindow *window;
@end
#import "AppDelegate.h"
#import "MainViewController.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[_window release];
MainViewController *mainVC = [[MainViewController
alloc]init];
self.window.rootViewController = mainVC;
[mainVC release];
return
YES;
}
#import <UIKit/UIKit.h>
@interface MainViewController :
UIViewController
@end
#import "MainViewController.h"
@interface
MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//1. ios 系统的文件机制SandBox
NSLog(@"%@",NSHomeDirectory());
//user开头的是电脑地址
//一 : 沙盒机制 : 在文件内部可以自由读写,无权访问文件夹外部的内容
// 1. Documents : 用来存储用户相关的内容,比如 : 数据库文件.不要在这个文件夹保存体积大的文件, 如果开启了icloud服务,系统会把这个文件夹的所有内容上传到用户的云盘上
// 2. Caches(缓存) : 缓存文件夹.系统缓存文件和一些第三方的默认缓存地址都是这个文件夹.清除缓存就是清空缓存文件夹.
// 3. Preference : 给开发者配置应用程序使用.
// 4. tmp : 临时文件夹,存储临时文件.清除缓存时一起清除掉
// 二. 简单对象写入本地
NSString *str =
@"大芊芊在吃西瓜";
// 1. 把字符串写入本地要先写一个路径 拼接一个文件路径
//参数一 : 要找的系统文件夹(documents,caches)
//参数二 : 在什么系统区域搜索文件夹
//参数三 : YES绝对路径/user... NO相对路径~/documents... 1.txt 文件路径
//返回值只有一个路径放入数组中
NSString *docPath =[
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES)lastObject];
NSString *strPath = [docPath
stringByAppendingString:@"/1.txt"];
// 2. 将字符串写入本地
// 参数一 : 要写入的路径
// 参数二 : YES保护线程安全 在写入过程是否保证线程安全
// 参数三 : 字符串的编码格式
// 参数四 : 错误
[str writeToFile:strPath
atomically:YES
encoding:NSUTF8StringEncoding
error:nil];
// 运行处地址 查找地址在文件中可以看到结果
//数组写入本地
NSArray *arr =
@[@"a",@"b",@"c"];
//数组拼接本地有两种形式xml或者plist
NSString *arrPath = [docPath
stringByAppendingPathComponent:@"2.xml"];
[arr writeToFile:arrPath
atomically:YES];
}
相关文章推荐
- poj 1679 The Unique MST (次小生成树)
- fix issues
- Qt5.4.2+win7的GUI界面设计
- IOS_UI_数据解析
- iOS 在UILabel显示不同的字体和颜色(转)
- [Bluetooth Core V4.2] VOL2, PartB, 7 Bitstream Processing
- Android之学习笔记 Contacts (一)ContentResolver query 参数详解
- EOE 高仿UI特效专辑网址
- 区分手势UITapGestureRecognizer
- C#中HttpWebRequest与HttpWebResponse的使用方法
- UIbutton在UIScrollview中highlighted延迟
- 安全学习之burp suite-Proxy代理后无法后续Forward的问题
- hdu5033 Building 凸包
- IOS第二天多线程-05NSOperationQueue 暂停,和恢复队列任务
- UICollectionView学习<2>之UICollectionViewCell的自定义
- UIKit类关系总览
- easy ui 菜单和按钮(Menu and Button)
- AI--N Queens Problem(Look-Back method)
- LED调光,PFM即pulse frequence modulation
- Java使用阻塞队列BlockingQueue实现线程同步