美文网首页
沙盒中存取删数据

沙盒中存取删数据

作者: 幻想no现实 | 来源:发表于2016-05-30 11:15 被阅读74次

    #pragma mark -存储数据

    -(void)SaveString:(NSString*)UrlStr

    {

    // 1.获得沙盒根路径

    NSString*home =NSHomeDirectory();

    // 2.document路径

    NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

    NSArray*data =@[UrlStr];

    NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

    [datawriteToFile:filepathatomically:YES];

    }

    读取数据

    - (NSArray*)readData {

    // 1.获得沙盒根路径

    NSString*home =NSHomeDirectory();

    // 2.document路径

    NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

    // 3.文件路径

    NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

    // 4.读取数据

    NSArray*data = [NSArrayarrayWithContentsOfFile:filepath];

    returndata;

    }

    删除数据

    NSString *home = NSHomeDirectory();

    // 2.document路径

    NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];

    NSFileManager * fileManager = [[NSFileManager alloc]init];

    [fileManager removeItemAtPath:docPath error:nil];

    相关文章

      网友评论

          本文标题:沙盒中存取删数据

          本文链接:https://www.haomeiwen.com/subject/xcaqdttx.html