How to add js file to my xcode project?

2019-01-16 18:26发布

问题:

I add some js and css files in my xcode left project tree. but when I build this project , I got the warning : no rule to process file '$(PROJECT_DIR)/js/builder.js' of type sourcecode.javascript for architecture i386

I think if I lost some setting with my project in xcode , but How to add some like js and css files? Thank you very much!

回答1:

When you add the JavaScript file, Xcode detects that the file is a source code file, assumes you want to compile it and automatically adds it to the Compile Sources build phase.

To stop Xcode trying to compile it and make it copy the file instead, expand your target in the Groups and Files list, remove the JavaScript file from the Compile Sources build phase and add it to the Copy Bundle Resources build phase.



回答2:

For Xcode 4, click on the main project, click on Build Phases. Open up Compile Sources and Copy Bundle Resources then you can then simply drag the files from one to the other.



回答3:

I got the same problem and I could solve this problem with simple technique in Xcode5. when you add/drag your HTML files into Xcode bundle you need add them by grouping as 2 types

1.assets

2.index.html

you need to add these two files only.

assets folder contains all HTML files like images,.js, content,css. All HTML files should be
included in assets folder. what I mean is you need to group all HTML files in assets folder as a single folder.

Then you drag that particular folder which contains ASSETS and INDEX.HTML files into Xcode bundle.

Then do some changes in your controller declaration and implementation sections. That's it you can run your application in simulator now.If any one have not understood my answer please let me know I will add clear information with screen shots.

I hope it will help some one..Thank you!

If anyone have any doubts still let me know i'll explain step by step