iOS gets the sandbox path and writes to the file

Source: Internet
Author: User

The. h file

The data collection form you need
@property (Nonatomic,strong) nsmutablearray *grouparray;//Array
@property (nonatomic,strong) nsmutabledictionary *alldict;//Dictionary

Determine if there are objects in the sandbox that are needed
+ (sharedatahandlemodel*) Sharedatahandlemodel;


Get the document path in a sandbox file
+ (nsstring*) documentpath;


Read data from a sandbox by file name
-(void) Readdatafromdocumentwithfilename: (nsstring*) filename;//array

-(void) Readdatafromdocumentwithfilenametodict: (NSString *) filename;//Dictionary


Write
-(void) Mywirtetofile: (nsstring*) FileName;

In the. m file

+ (sharedatahandlemodel*) Sharedatahandlemodel
{
If you create a new
if (Nil==sharemodel) {
Sharemodel=[[sharedatahandlemodel Alloc]init];
}
return Sharemodel;
}


Get the document path in a sandbox file
+ (nsstring*) documentpath
{
Nsarray *patharray=nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
return patharray[0];
}


Read data from a sandbox by file name (array)
-(void) Readdatafromdocumentwithfilename: (nsstring*) FileName
{
Stitching file path
NSString *filepath=[[[self class]documentpath]stringbyappendingformat:@ "/%@", FileName];

Nsarray *temparray=[nsarray Arraywithcontentsoffile:filepath];

Self.grouparray=[nsmutablearray Arraywithobject:temparray];


}

Read data from a sandbox by file name (dictionary)
-(void) Readdatafromdocumentwithfilenametodict: (NSString *) fileName
{
Stitching file path
NSString *filepath=[[[self class]documentpath]stringbyappendingformat:@ "/%@", FileName];

NSString *filepath=[self appendpath:filename];//Use the following encapsulated
Self.alldict=[nsmutabledictionary Dictionarywithcontentsoffile:filepath];
}




Packaging
-(nsstring*) Appendpath: (nsstring*) FileName
{

Stitching file path
return [[Self class]documentpath]stringbyappendingformat:@ "/%@", FileName];

}


Write
-(void) Mywirtetofile: (nsstring*) FileName
{
NSString *filepath=[self Appendpath:filename];

Nsmutablearray *a=self.grouparray[0];
[a writetofile:filepath atomically:yes];


}

iOS gets the sandbox path and writes to the file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.