Rookie beginner iOS, tidy up the way to get iOS various sandbox paths __ios

Source: Internet
Author: User
Tags tidy

In the beginning of iOS programming, there are many do not understand and do not understand the place, in the spirit of sharing, will learn to use some of the things written out, if there is not the right place, I hope everyone correct.

This is a tutorial on the various folders under the iOS related knowledge.

First of all, we should know that under iOS, there are a total of 4 folders, respectively, Documents,tmp,app,library, where the app we generally have less contact, because there are some applications, seemingly because of the signature and other reasons, We can not modify the contents of this directory at runtime otherwise it may cause our application does not work properly (this Part I do not understand, the proposal wants to know more about the children's shoes to check again).

and documents this directory, used to store user data and other related information, but also our main application of the directory.

TMP directory: This directory is the same as its name, which is used to store temporary files and some temporarily unwanted information.

The library directory, under two accept, respectively, caches and Preferences, where the Preferences directory is used to store the application's preferences file. The caches directory: a support file for application-specific purposes.


Here is the code to get the individual directories:

Methods for obtaining the Documents directory path:

nsstring* documentpath = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) OBJECTATINDEX:0]; 1
NSLog (@ "%@", documentpath);//2
Step 1 above is the way to get the document directory. and 2 of the function is to output this path, for detection, here I mention to beginners a little bit of my mistake, is that I have to follow the directory layer to find the file, the results can not be found in any case, it is because there is a layer of files are hidden, so if you want to manually find, you need to set hidden files visible, The method is simple and is entered at the command line as follows:

Showing: Defaults write Com.apple.finder appleshowallfiles-bool true
Hiding: Defaults write Com.apple.finder Appleshowallfiles-bool false

Of course, here just by the way to show/remove hidden files, I do not recommend manual to find, we only need to click on the Finder, and then click "Go", the address to copy in the OK, convenient and quick.

The code to get other paths is similar:

Get Library directory path:

NSString *librarytpath=[nssearchpathfordirectoriesindomains (Nslibrarydirectory, NSUserDomainMask, YES) OBJECTATINDEX:0];  
Get the TMP directory path:

NSString *temppath=nstemporarydirectory ();

The above, is commonly used directory path to obtain the method, then, when we want to specifically obtain inside a certain file path of how to do it. Following

    NSString *filename = @ "1.txt";//1
    nsstring *localdir = [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) OBJECTATINDEX:0];//2
    NSLog (@ "%@", Localdir);
    NSString *filepath = [Localdir STRINGBYAPPENDINGPATHCOMPONENT:FILENAME];//3
In the code above, the first step is to write down the name of the file, the second step is to get the document path, and the third step is to get the file path.

Of course, this is the case where we know exactly what the file name is, or when we're going to create 1.txt, so we can use the following code when we don't know what's in it and need to know what's inside it:

NSString *path=[[nsstring alloc] initwithstring:localdir];
Nsfilemanager * FileManager = [Nsfilemanager Defaultmanager];
Nsarray  *arrayforfile = [FileManager  Directorycontentsatpath:path];

Well, the above is what I used in the study of some things, if there is any part of the wrong, I hope you tell me, I must humbly correct.





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.