How do I add files to the Copy Bundle Resources build phase with an Xcode4 Project Template - iphone

I'm working on an Xcode 4 project template and I'm struggling with controlling the files that get added to the Copy Bundle Resources build phase--header files get added that I do not want to be copied into the project bundle and a file that I do want to be copied does not appear in this list (a custom .framework file that contains both the static library and image resources).
It seems like Xcode automatically builds contents of this build phase from the Nodes section in the project template; if it's a .framework, it automatically gets added to the linked libraries, if it's a .m, it automatically gets added to compiled sources, and everything else gets added to the Copy Bundle Resources.
I'd be grateful for any direction on this one!
Update:
To clarify, I'm attempting to create an Xcode project template that, when used, creates a new Xcode project that includes the specified files from the template in the Copy Bundle Resources build phase.

This should help. After the Class-Resources key-value pair, you can add files somehow. I couldn't figure that out but I'm sure you can find it somewhere.
EDIT: Actually, i think an easier way is to in the Definition part, after the Path key, add a TargetIndices key (an array). With some experimenting you should be able to find out what value to put on one item of that array to put it in the Copy Bundle Resources build phase.

Yes, Xcode tries to manage this for you. If after adding a file, it did not did what you want, then change it. It's guesses are "usually" correct "most" of the time. :)

Related

Xcode generated CoreData files cannot be processed by Copy Bundle Resources build phase

I added CoreData to my app MY_APP:
I defined the data model by creating a xcdatamodeld file containing
a single entity XXX with a few attributes.
Using Xcode/Editor/Create NSManagedSubclass, Xcode created 2 files, XXX+CoreDataClass.swift and XXX+CoreDataProperties.swift.
I wrote a little code to test storage and fetch back from core data, and everything works fine.
The problem:
At the beginning of the build phase, I get 3 warnings:
warning: The Swift file "/Users/reiner/Library/Developer/Xcode/DerivedData/
MY_APP/Build/Intermediates.noindex/MY_APP.build/Debug-iphonesimulator/
MY_APP.build/DerivedSources/CoreDataGenerated/MY_APP/XXX+CoreDataClass.swift"
cannot be processed by a Copy Bundle Resources build phase (in target ‚MY_APP‘)
warning: The Swift file "/Users/reiner/Library/Developer/Xcode/DerivedData/
MY_APP/Build/Intermediates.noindex/MY_APP.build/Debug-iphonesimulator/
MY_APP.build/DerivedSources/CoreDataGenerated/MY_APP/XXX+CoreDataProperties.swift"
cannot be processed by a Copy Bundle Resources build phase (in target 'MY_APP')
warning: The Swift file "/Users/reiner/Library/Developer/Xcode/DerivedData/
MY_APP/Build/Intermediates.noindex/MY_APP.build/Debug-iphonesimulator/
MY_APP.build/DerivedSources/CoreDataGenerated/MY_APP/MY_APP+CoreDataModel.swift"
cannot be processed by a Copy Bundle Resources build phase (in target 'MY_APP')
These 3 files are not listed under MY_APP target/Build Phases/Copy Bundle Resources.
My questions:
Is anything wrong with my build setup, i.e. what is the reason for these warnings, and how can I avoid it?
Remark: This question relates to a different framework (core data), but is similar to this one, which does not have an answer yet.
EDIT:
My project has 2 targets, for iOS and for watchOS. Until now, core data was used only on iOS.
I tried now to enable it also for watchOS, but I got an error, because the .xcdatamodeld was not yet in Build Phases / Copy Bundle Resources.
As soon as I added it there, core data was executed correctly on the watch.
BUT: I got the same 3 warnings mentioned above, this time additionally for the watch extension target (altogether 6 warnings).
Maybe this a useful hint.
EDIT:
I contacted Apple, and they provided a solution:
When an Xcode project „xxx“ is created with the coreData option on, a core data model file „xxx.xcdatamodeld“ is created and added to the target Build Phases Compile Sources.
Say, one adds there an entity „Entity“ with an attribute „attribute“.
If one selects in the Xcode project navigator this model file and opens the file inspector, there is an entry „Code Generation“ which is set to Swift by default. This creates the 2 files Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift automatically, but they are not shown in the project navigator.
Building the project succeeds, and one can use a property Entity.attribute as usual in the code.
However:
If one selects the xcdatamodeld file in the Xcode navigator, the Xcode Editor menu has an entry „Create NSManagedObject Subclass…“. If one selects this entry and there the xxx data model, the 2 files Entity+CoreDataClass.swift and Entity+CoreDataProperties.swift are created again and shown in the project navigator, and added by default to the target.
This means that these files are added twice, thus the warnings.
So the solution is not to use this editor command, and I don’t know what it is for…
EDIT 2:
My fault; I was looking at the wrong place:
Open the xcdatamodeld in the project navigator.
In the pane right of it, select an entity.
At the top right, open the inspector pane.
At the top right of it, select the data model inspector.
There is an entry „Codegen“ where one can select Manual/None.
If this option is selected, no code is automatically generated from xcdatamodeld, i.e., one can manually (by using the editor command) create NSManagedObject subclasses that can be added to the target Compile Sources section, as required.
Previous answer:
There are apparently 2 ways to use CoreData, either 1) by using only the PROJECT.xcdatamodeld file, which is then added to Compile Sources Build Phase, or 2) by creating a NSManagedObject subclass using Xcode’s Editor/Create NSManagedObject Subclass command.
If 1) is used, everything works fine, but one has no property access to the entity used.
If 2) is used, Xcode creates the 2 files ENTITY+CoreDataClass.swift and ENTITY+CoreDataProperties.swift. These 2 files are added to the Compile Sources Build Phase, but PROJECT.xcdatamodeld must not. If one does anyway, one gets the build error „unexpected duplicate task“. But if one does not, the project builds without errors and warnings.
However, when run, the instruction
let entity = NSEntityDescription.entity(forEntityName: "MyEntity", in: managedContext)!
fails, because it does not find the data model.
A workaround is to add PROJECT.xcdatamodeld to target / Build Phases / Copy Bundle Resources. Then the code executes fine, but one will get the warnings that I described in my question.
For me what caused the issue was having the .xcdatamodeld file in the Copy Bundle Resources step within Build Phases for the target specified in the warning: in your case, MY_APP. I removed that file from the Copy Bundle Resources step and all the warnings went away.
An approach to dealing with an Xcode which seems to be getting more and more buggy with each release in recent years:
Quit and relaunch Xcode.
If that does not work, do a Show Package Contents on the .xcodeproj package and open the .pbxproj file in a text editor. Search the file for occurrences of XXX+CoreDataClass. The search the file for occurrences of some other .swift file which does not create this warning. Compare the two search results. It may be necessary to manually edit the .pbxproj file.

How to compile Object(*.o) files added with iPhone app?

I have created a simple native iPhone app. This project contains with c,c++ source files for doing some operations. Its radio tuning app, thats work fine. I want to give a source code to some one, and want hide all of source code c,cpp file (Because strangers don't want to see my code). So what i did is , i have compiled iPhone app and collect all (.o) files from build path and added to my resource folder.
For example if my application have these two files
radio.c
radio.h
when i build radio.o present on build path directory. my build path is (/Users/Macuser/Projects/Radio//build/Radio.build/Release-iphoneos/HDRadio.build/Objects-normal/armv7/radio.o).
So i copied radio.o file and added to my source code directory, and i removed the radio.c and radio.h file. When i compile it gives a error, radio.h file not found.
What could be the problem here? please let me know. Thanks in advance..
Note:
When i add radio.h file to my project it compiles successfully. I don't want to see my radio.h and radio.m file. is this possible?
There must be some other file in your project that is importing or including radio.h. Your .o file is used for linking but import/include dependencies are resolved when compiling the source. (A .o file is not source.)
If you don't want to provide .h files, the way around that is to create a static library to contain all the .o files that depend on each other. (However, to call any functions inside your library, the person still needs a .h with the declaration of public functions.)

Xcode 4 embedded resource prevention

In XCode4, is there a way to have a 'resource' (i.e. a CSV used to load a sqlite database) that is there for project purposes, but not have it compiled into my project? So my final app doesn't include it? I can't seem to see to to have this facility.
Thanks
Assuming you do not want the file get into your .app file, One solution i can think of is, do not include 'Target' when adding the file to the project. If you want to exclude your already added file then
Choose the target
Go to Build phases
Expand copy bundle resources
Select your resource file and remove it.

How do I properly add existing source code files to my Xcode project?

I'm new to iPhone development and I'm still getting familiar with the Mac dev environment, including Xcode. I want to add some 3rd party code to my iPhone project, but when I add the "existing files" to my Xcode project, I'm presented with a dialog box that has far too many options that I don't understand and, as such, my project isn't working. When I #import headerfilename.h, I get a build error that reads headerfilename.h: No such file or directory.
alt text http://joecrotchett.com/images/misc/fileadd.jpg
Can anyone explain to me what all these options mean or give me a link to some documentation that can? I'm having a hard time finding anything in Apple's docs.
Which options do I want to choose to add existing source code files to my Xcode project? I should note that the source code files that I'm trying to add are located in my project/Classes/frameworkname/ directory.
After they're added, do I need to reference this new code directory in my project settings anywhere (i.e. some kind of header file directory variable)?
Thanks so much!
Update: I found the following answers/responses on the apple dev forums that were very useful and helped me fix my issue...
To make it simple :
- if you do not check the copy option, the file stay where it is.
- if you check it, it is copied in your project folders In the first case
(what it seems you are doing) you need
to tell the compiler that the header
files are in another directory :
- project info -> build -> search paths -> User Header Search Path : add
the directory from where you took the
header file Hope this will help
You have discovered the most confusing
dialog box that ever came out of
Cupertino. Six years of Xcode, and
this thing still is partly a mystery
to me. To even get that far, I had to
make many test projects to try and
reverse-engineer what this thing does.
The "Copy" box means that it will copy
the files as they are right now, into
the project. If this box is not
checked, then it just references those
files during a build and copies them
as they are at THAT time. For source
code, you want the Copy box checked.
The "relative to" is a total mystery
to me and I can't help you with that.
I usually leave it however it is
already set. Does it mean relative to
where they are on disk, or the
arrangement in Xcode, or in the
bundle? Who knows. The last 2 radio
buttons SEEM to mean that it will
either re-create the folder structure
of the folder you are adding, or just
put "fake" folders in Xcode that point
to the real folders. This is probably
your problem - you are adding source
code that is not all at the top level,
and when it goes to find it, it does
not re-create the hierarchy. Others
can supply a better way, hopefully,
but what I would do is put all of the
source in one folder and add that,
using the Copy box. Then in Xcode you
can make whatever bogus folders you
want and put the source file names in
those fake folders.
This is from the Xcode user guide:
"The project navigator shows projects, groups, folders, and files:
The project or projects in your workspace window are the highest level
of the hierarchy in the project navigator. Open the project’s
disclosure triangle to see the groups, folders, and files in the
project. Select the project to display the project editor, where you
can view and edit project and target settings.
A group appears in the project navigator as a yellow folder icon. The
group does not represent a folder on disk. Although you can organize
your project in Xcode to reflect the organization of files on disk,
moving files into and out of groups does not affect the content of the
folders on disk, and moving files on disk into and out of folders does
not affect the content of the groups in the project navigator.
A folder is a reference to a folder on disk and appears in the project
navigator as a blue folder icon. The contents of the folder in the
project navigator reflect the contents of the folder on disk. It’s
important to note, however, that the files that appear in a folder
icon in the project navigator are not part of your project unless you
have added them to the project explicitly (in which case they appear
directly under the project or in a group, as well as in the folder).
You can view and edit the files in a folder, but to move files in and
out of the folder you must use the Finder.
A file in the project navigator is a reference to a file on disk."
I think usually the default option is the best one. If you want to add into some group, you can tick on the "Copy Item to Destination group"
You don't have to change any project settings after adding
And if you want to add the whole framework code, please choose add existing framework
Copy items into destination group's
folder (if needed)
Well, only if you want it to copy the files. If you are happy with their existing location and don't want it to copy them, don't select it (that's what I do).
Reference Type:
A total mystery to me
Text Encoding
Self explanatory
Recursively create groups for any
added folders Create Folder References
for any added folders
Leave this as the default and then organize the folders in your Xcode project any way you want.
Add to targets
If you add an additional target to your project, e.g. for iPhone vs. iPad versions, then not noticing that it has by default added the files to just one of them (at random?) can cause headaches.
Also, make sure you add the new header directory to your search paths in Project Settings > Build > Search paths. I think that's what's causing your problem.
Hope this helps, I remember how confusing this was to me at first.
If you want to add an Framwork Bundle, just add is as one. Add -> Existing Frameworks

Xcode iPhone app package missing files

I'm struggling to figure out what exactly it is that decides which files go into the .app-package when compiling an application in Xcode. I've noticed that most image files go there automatically, while others like yaml-files or psd don't, and I cant find anywhere to set this. So, how do you do this?
Look at the build phases for your application target. You'll find that recognized image files were added to the Copy Bundle Resources phase. To copy files of a type that Xcode doesn't recognize, you can add a Copy Files build phase.
If all else fails, read the documentation.