[Ios]リソースファイルの Acquisition method

Source: Internet
Author: User

リソースファイルのパスを get するためには developed Natsumi Sato installed able.

--------------------------------------------------------------------------------
How to obtain リソースファイルの?
--------------------------------------------------------------------------------
ファイル name "test.db"のパスを obtained able.
NSString *filename = @ "Test.db";
NSString *resourcepath = [[NSBundle mainbundle] resourcepath];
NSString *filepath = [ResourcePath stringbyappendingpathcomponent:filename];

ただしローカライズした International occupies method ではデフォルトのファイルしか obtained できない.
そのため method で obtained beauty square が good さげ.

NSBundle *mainbundle = [NSBundle mainbundle]; Pathforresourceには Hiroki Zhang Zi めない containing. NSString *filepath = [Mainbundle pathforresource:@ "Test" oftype:@ "db"];

ちなみにサブフォルダを made into beauty は のようにindirectoryにサブフォルダ named able.

NSBundle *mainbundle = [NSBundle mainbundle]; NSString *filepath = [Mainbundle pathforresource:@ "Test" oftype:@ "db" indirectory:@ "db"];

"リソースフォルダにサブフォルダを as る method"
リソースファイルをプロジェクトにコピーするときに"create folder references for any added Folders"を select drivers able.
プロジェクトエクスプローラー on でフォルダが Green くなっていればサブフォルダの made occupies success している.


--------------------------------------------------------------------------------
プロジェクトの all リソースファイルを obtained able method
--------------------------------------------------------------------------------

Nserror *error;
NSString *resourcepath = [[NSBundle mainbundle] resourcepath];
Nsarray *directory = [[Nsfilemanager defaultmanager]contentsofdirectoryatpath:resourcepath error:&error];
For (NSString *str in directory) {NSLog (@ "filename:%@", str);
}

[Ios]リソースファイルの Acquisition method

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.