IOS_UI_本地存储

#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(NSDocumentDirectoryNSUserDomainMask, 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];

    

    

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值