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