Sometimes in the project to add some configuration files and then read the corresponding configuration information in the program, the following is the way I organize to get the project configuration file (. plist) Path:
1. Get the sandbox path and then append the configuration file
Func documentsdirectory ()->string { var paths = Nssearchpathfordirectoriesindomains ( Nssearchpathdirectory.documentationdirectory, Nssearchpathdomainmask.userdomainmask, True) var Documentsdirectory = Paths.first as! String return Documentsdirectory}println (Documentsdirectory ())
At this point the console prints the following information (I am running inside the emulator):
/users/it/library/developer/coresimulator/devices/46084088-c7ae-47c9-838a-2e6835f87e53/data/containers/data/ Application/66f88024-7c96-4a74-bdb7-7a7422f39774/library/documentation
Paste the above path into the Finder->go->go to folder, note the sandbox path to remove the last documentation after the carriage return can be seen similar to the following interface
On the basis of the above path plus the name of the configuration file can and to the path of the configuration file, such as the checklist.plist after the final file name is Documentationchecklist.plist
2. Use NSBundle to get the path, this way is relatively simple:
Func GetFilePath ()->string { return Nsbundle.mainbundle (). Pathforresource ("Checklist", OfType: "Plist")!} println (DataFilePath ())
At this point the console prints the following information:
/users/it/library/developer/coresimulator/devices/46084088-c7ae-47c9-838a-2e6835f87e53/data/containers/data/ Application/66f88024-7c96-4a74-bdb7-7a7422f39774/library/documentationchecklist.plist
Ways to get the configuration file path in Swift