Get subdirectories for iOS apps

Source: Internet
Author: User

When developing an iOS app, we often need to categorize the footage and put it in the appropriate subdirectory.

When you develop your code, you need to access the footage, and you need to get the corresponding subdirectory path. So how to get it?

Get the app Path

First, find the path where the app resides.

NSString *bundlepath = [[NSBundle mainbundle] bundlepath];
Get subdirectory Path

If you have a subdirectory named images, you can get its path in the following way.

NSString *imagepath = [Bundlepath stringbyappendingpathcomponent:@ "Images"];

Find this path is OK, starting from here, you can do whatever you like, such as traversing the subfolders of the desired file.

Don't be happy, too early.

Even with the code above, you don't necessarily succeed, why? Because iOS app default file organization structure is flat (flat) mode, that is, no subdirectories! You can see many directories in Xcode, but there are no subdirectories in the generated file. Cause the above code to fail. What to do?

    1. Drag the subdirectory you want to add to Xcode (or right-click the project selection-add file to project),
    2. In the popup dialog box to select "Create Folder References for any added folders", remember!

What if my subfolder has been added to the project, but no "Create Folder References for any added folders" is selected?

It's okay, just delete him and remove References when you choose. Do not move to Trash, and then add it again by following the steps above.

Another method is set under the Copy Bundle resources option in Build parse. Add the subdirectories you want to copy to, as shown in.

Folders of different colors

In Xcode, there are two colors of the folder, one is yellow, one is blue, only the blue folder will be copied to the app directory, the yellow folder is only used to organize files, does not represent the final structure of the application!

Happy Coding!!!

Get subdirectories for iOS apps

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.