Associate an image folder for a a specific target - ios

I have created a projects witch contain two targets ( i have duplicate Target1 to have Target2). i have many images in the project. I would like to associate some images to one target and some others to the second target. I doing this by selecting one image.
my question:can i associate a fonder of images to a Target ? if yes how i can do this ?
thanks for your answers.

Yes, it's possible: well folder itself has no target membership but you can easily associate all files from one folder to one target and files from other folder to the other target. Files in these folders can have the same names of course.
You can have two separate folders on disk, let's say images_t1 and images_t2.
Drag images_t1 folder into project tree and when asked for "add to target" you only check Target1 checkbox. For images_t2 you only check Target2 checkbox - that's it.
I just retested it and target membership of imported files (inside the two folders) is correct.
But note, if you are planning to use this images with Interface Builder you might run into minor XCode bug - mixing images. There is a workaround for that, but it's not pretty. Check Xcode 4, Interface Builder, two targets with seperate .xib (image resources with same names).
This bug is visible only during .XIB editing - everything is fine once apps are compiled.

Related

How can I add file to project in Xcode 9?

I created a new project in xcode 9.
I want to add image file to project.
When I delete this file from desktop,
Image file appears in red?
But in project folder, I find this image file.
In Xcode 8 its working fine,
Any idea?
It is an Xcode9-beta (9M136h) bug. I don't know if it has been resolved in beta3 or not. Copy items if needed copies the file to your project directory but still links to the original file.
What I do is, after dragging the file to my project, I select the folder icon (see red circle in the image below) from File Inspector and point to the copied file in the project directory.
#pesch's approach works too. First copy the image to your project folder and then drag it to Xcode.
Xcode 9 allows to have folders in Xcode synced with folder in your Finder structure. I assume this is a bug since Xcode 9 is still in beta and you are "ticking" the Copy items if needed.
Try moving the image to your project folder yourself and drag it from there to Xcode.
This is what you would do to leave the Copy items if needed box unticked since you are doing it yourself.
It looks like a XCode 9 bug. If you check the Full Path of your image file in Identity and Type Tab, it would show the location of the deleted file, hence the deleted(red) color.
You can delete that reference and can use Add File To.. option to add the reference of (already) copied image from your source folder.
Although this is not resource related (images, etc). The issue that I'm currently facing with the Xcode 9.0 GM build is that adding the items to the project does not actually added them to my targets, although I selected them.
Step 1 - Add Files to Project
Add New Files and Select your targets
Step 2 - View Files in File Inspector
You can clearly see in the file inspector that it is not added to those targets accordingly.
Step 3 - [Fix] Add New Added File to Targets
To Fix this, just check the targets that the files should be added to and you should be good :)
I have seen this issue in Xcode 9.0 GM (build 9A235, same as the current release). It's intermittent; sometimes 'Copy items if needed' is honored, sometimes not.
In one case it seemed to be triggered by the presence of source control. I was working through an online tutorial where the provided project had no source control. Adding files here did honor the 'copy items' checkbox, but if I made the provided project a git repository first, adding files ignored the checkbox every time.

Assets using targets with Xcode

I'm working with an iOS app with múltiple targets and at this moment, I have a critical doubt.
The project has two targets, target A and B, and each target has different set of images.
My question is:
If I upload the target A to iTunes Connect, this target will contain also the images of the target B, or this target (A) only will contain her images?
Target A and Target B would have the same images only if you set it up as such. Each target can have its own set of source files and assets. If you look select items (whether it be source files, frameworks, or other asset files) and have the File Inspector on, you'll see something called Target Membership. This indicates which target it belongs to.
When you Add File(s), there is also a dialog that indicates which targets to add it to.
The Build Phase of the target will also show you the files that are compiled as well as files that are copied into the binary and the libraries used to link.
Note there are multiple ways to add/remove files from the target.

Creating two targets in XCode 4

I want to create two targets for my application iphone and ipad version.
My question is : Do I need to copy all the files from one target to another , because i found out that there are two AppDelegate files in my project, and what about resource and library files? This is the first time when i am trying to setup a multitarget project.
No, there is no need to copy source files. You can click on each file and tell Xcode which target they belong to (The Target Membership section of the File Inspector tab in the right pane).
Any files that are meant to be different (like the delegate classes you mention) obviously won't be added to both targets.

How to share files between two xcode projects in workspace?

I learnt about Xcode workspace .I know how to share the static library but i want to share the files between two xcode projects in workspace and is it possible to run multiple targets at a time?Can you provide me the information of how to do this.
Thanks in advance
Sharing files between projects in the same workspace is easy, even if the projects are on the same level (no subprojects):
Assume you want to share constants between Project1 and Project2, and these constants are defined in a file SharedConstants.swift, which is defined in Project1.
In order to be used in Project2, it must be compiled there.
Thus, activate in the project navigator Project2, select the target and open the Build Phases tab.
Open there Compile Sources by tapping the little triangle left.
Tap the + button below the listed sources for this target. This will show you a list of files of Project2. There you cannot select your shared constants, because they do not belong to this project.
However left bottom is a button Add other…
Tapping it will open a standard file selection window where you can select SharedConstants.swift from Project1.
After tapping Open, a 2nd window opens with a Destination: Copy items if needed checkbox.
Important: Do not check this box!
If you would check it, a copy of SharedConstants.swift would be used in Project2, and any changes that you make in Project1 would not be visible in Project2. Instead, it you uncheck it, only a reference to SharedConstants.swift in Project1 would be used in Project2, and any changes will affect both projects.
To share the files you can probably use the bundles
Targets are manipulated with Schemes in Xcode 4, you can launch several targets in the same time if you select the different destinations (with OS X you can probably have the same destination :) )
You'll see a little triangle below the stop button indicating that you can long-press it to select which operation should be terminated:
You can switch the console with the popover at the Debug area where you see the target name and icon - that's a button.
You can drag Xcode projects into other Xcode projects to nest them.
More info here:
How should I manage dependencies across projects in an Xcode workspace?

Multiple versions of iTunesArtwork in one project?

I have a single Xcode project with several targets, each spitting out a different app with a different icon. The icons are in their target-specific resource folders so they don't collide.
But the 'iTunesArtwork' file (i.e., the icon used for display of Ad Hoc builds in iTunes) must be placed in a specific location (Project Root), and named exactly that, so multiple versions can't coexist.
Any workarounds?
You must be able to do the same trick with the Artworks file, store several files (with the same name) at different folders, add them to the project respecting the files Target Membership (File Inspector section).
They don't have to be in the project root. If there're several icon files at different project folders, each icon is a member of it's own target, then you have different target icons with the same icon name (and naturally the only icon file is copied to the bundle root).
You might need to have one of the icons at the project root folder (e.g. it might be copied there for you by Xcode), but during the build the icons should be copied from the folders referenced in the project rather than from the project's root folder.

Resources