Ways to get the configuration file path in Swift

Source: Internet
Author: User

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

Related Article

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.