The above is the dictionary data (picture)
Find the path to the application package first
NSBundle *bundle = [NSBundle mainbundle];
NSString *path = [bundle Bundlepath];
And then read out all the files under the path.
Nsfilemanager *FM = [Nsfilemanager Defaultmanager];
Nsarray *allfile = [FM Contentsofdirectoryatpath:path
Error:nil];
NSLog (@ "%@", allfile);
Find the file with the picture and add the array
Nsmutablearray *imgfiles = [[Nsmutablearray alloc]init];
[Allfile enumerateobjectsusingblock:^ (id _nonnull obj, nsuinteger idx, BOOL * _nonnull stop) {
NSLog (@ "%@", obj);
NSString *file = (NSString *) obj;
if ([[[File Pathextension] isequaltostring:@ "jpg"]) {
NSString *appname = [File stringbydeletingpathextension];//remove extension
Encapsulate data as a dictionary
Nsdictionary *dic = @{@ "AppName": appname,@ "AppIcon": File};
The dictionary is placed in the array
[Imgfiles Addobject:dic];
}
}];
Get the path to the file and write
Nsarray *arr = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *document = arr[0];
NSLog (@ "%@", document);
NSString *plistpath = [Document stringbyappendingpathcomponent:@ "/imgstore.plist"];
Nsfilemanager *imgfilemanager = [Nsfilemanager Defaultmanager];
[Imgfilemanager Createfileatpath:plistpath
Contents:nil
Attributes:nil];
BOOL r = [Imgfiles Writetofile:plistpath atomically:yes];
if (r) {
NSLog (@ "Write succeeded ....");
}
iOS Learning Note 13-Dictionary data write plist