I am using Xcode and currently my images are on desktop , what is the right way to move them in to the folder?
(when I just copy paste them my project not builds).
is there any easy way to do that without re linking the images 1 by 1 ?
1.In the Xcode project navigator, select the destination project or group for the item you want to add.
2.Choose File -> Add Files to “”.
3.Select the file or folder to add.
4.Select destination, folder, and target options, and click Add.
or
Just drag and drop your desktop folder into Xcode project.
In your case the images are on desktop. So you have to check Copy items into destination group’s folder option. Select this option to create a copy of the selected file or folder in the workspace. Do this if you want to delete, move, or rename files or folders in the workspace without altering the original versions on disk.
For more details : Developer.Apple : Adding an Existing File or Folder.
Related
I'm curious when using Xcode.
I always need to choose an option when copying the open source class files I need for my project.
The options are "Create groups" and "Create folder references".
I've read the difference between the two already.
But it is not understood at all.
When I chose one of the two options, I deleted the file from my project and the open source class file was deleted at the same time.
I do not want it.
I want to always exist as an independent file. What should I choose?
It took me a while to understand the difference between those two options so I thought I'd share:
I'm writing this when Xcode 12 is the current version
The biggest difference is how the imported folder / file will be accessible from the finder. Let's say you want to import a new folder to your Xcode project. When you choose Create groups Xcode will import your new folder and create a group (the yellow icon). When you go to your project's directory (using Finder) you should see a folder named like the one you've just imported, but any additional files you put to this folder trough Finder won't be visible in your Xcode project.
When you choose Create folder references the imported folder will have a classic blue folder icon in Xcode. This new folder will also be visible when you go to your projects directory, but now every new file you put there will also appear in your Xcode project.
If you want to know more just read this explanation http://www.thomashanning.com/xcode-groups-folder-references/
It's pretty straightforward and easy to understand.
There are two types of any Xcode project structure organization:
filesystem project structure (inspectable with Finder.app)
IDE project structure (inspectable with Project Navigator in Xcode's navigator area.)
Xcode relies on filesystem organization by keeping a reference to a "physical" file or folder. That is why you may have all the classes, images, plists, and other parts of your projects stored in the same folder, while the references to these parts are being kept organized into respective groups within Xcode project.
When you create a group, it affects the organization of your project in Xcode. When you create a group with a reference folder, it creates both, a group in Xcode project and a folder in your filesystem.
However, since Xcode 9 it seems like, Apple enforces filesystem project structure to correspond to Xcode project structure. It means, that you explicitly has to choose "New Group without Folder"
Added files and folders from Finder into the Xcode group. Xcode 10.2.1. Just take a look at the examples without Copy items if needed
Files
Common behaviour for create groups and create folder references
Rename a file from Finder does not rename the file in Xcode, as a result Xcode doesn't handle it and it will mark them by red color.
Rename a file from Xcode rename the file in Finder
Change a file from Finder change the file in Xcode and vice versa
Remove to trash a file from Xcode change the file in Finder and vice versa
Add a file from folder in Finder does not add the file to group in Xcode
Folders
Common behaviour for create groups and create folder references:
Rename a folder/group from Xcode rename the folder in Finder
create groups
If you choose create groups, then the corresponding folder appears with a yellow icon in the project navigator.
It is just a virtual folder. It useful during development when you copy a file and it is not compiled and you do not have a time to make changes in it and want only to check if a project works. So you can just remove a reference from a file. It will not be removed from a folder as a result you will be able to add this file again.
Rename a folder in Finder does not rename a name of group in Xcode. You steal can work with group but previous content inside although visible but unavailable
Add a file to a folder in Finder does not add the file to group in Xcode
Add a file to a group in Xcode does not add the file to folder in Finder
Remove a folder in Finder does not remove the group in Xcode. You steal can work with group but previous content inside although visible but unavailable
create folder references
If you are choosing create folder references, then the folder appears with a blue icon in the project navigator.
It is a real folder and any changes will be reflected
Rename a folder in Finder does not rename a name of folder in Xcode. The previous content is gone and you can not work with this folder
Add a file to a folder in Finder adds the file to folder in Xcode
Add a file to a folder in Xcode adds the file to folder in Finder
Remove a folder in Finder removes the folder in Xcode.
[Copy items if needed]
Create folder references:
Useless because even if you list this folder to be included with a target, Xcode won't include any of its contents in that target and there's no way to click on something in the folder and see which targets it's included in.
Create groups:
This is the only way to go, if you want to include any of the folders' contents in a build target.
I want to have all my image files in a folder so that I can obtain all of them at the same time. I think the path should like this ...MyApp.app/image folder/1.png.
But when I drag them into xcode with folder references created, there is no folder. The path is always MyApp.app/1.png.
Also, I think I've dragged the files into the app several times. How to delete the files? It's not enough to just delete the references.
If they are not visible in project navigator, that means that you have no references to them and you can delete them directly in finder.
You are likely to have moved every image to a group rather than a folder. A group is just a convenience in Xcode project navigator. It has nothing to do with file hierarchy.
To keep them in a folder, right-click project navigator. Select new folder, drag your files to that folder. When they are visible in your project navigator, make sure that they are all linked to your project. I.e they are all check market with your project in the right pane.
It important to drag them to the folder and not just outside of it.
Here's the easiest way to do this in Xcode:
1)
Put all your images into a folder and then drag that folder into the list of files in your Xcode project. That step looks like this:
2)
A sheet will drop down in Xcode and ask you how you want to add these files to your project. It looks like this:
There's a checkbox at the top there that says "Copy items into destination group's folder (if needed). You will check this if you want to copy your folder full of images into the same place where your source code is found in your Xcode project.
3)
When you're done adding, here is what your project should look like in Xcode. Notice that the folder color is blue. That means it's a folder reference. This folder will be copied into your built application.
Have been inputting and testing some sample code and everything seems to be ok. Just that suddenly I am running into this very frustrating problem of trying to add an icon to the project. Have downloaded an icon file (extension : icns) to my desktop and dragged it to the "Resources" group in xCode. Then a dialogue comes up from xCode where I checked the 2 options : "Copy items into destination group's folder (if needed)" and "Recursively create groups for any added folders". But when I press the "Add" button, an "Alert" message box would come up. It says "Could not copy the icon to ...". Hope that someone knowledgable in this area would give me some hints...
This failure message usually results from attempting to add a file (that is outside the project folder), when a file with that name already exists in the target location within the project folder.
For example, let's say your project folder is ~/Developer/CoolProject/, and the Xcode project is at ~/Developer/CoolProject/CoolProject.xcodeproj. If you drag an image, coolImage.png, from your Desktop to Xcode with the options set as you described, Xcode will copy the image file to ~/Developer/CoolProject/coolImage.png. If you then repeat this same procedure, it will fail the second time with that error message.
What I would do is, in the Finder, check inside your project folder to see if the icns file has already been copied into the project folder. If there's a copy of the icns file already in the project folder, and that icns file isn't listed in the Groups & Files list in Xcode, you can resolve the problem by dragging the existing copy (that's inside the project folder) into the Xcode project window to bring up the Add File dialog. You can keep the same options as before, and this time, Xcode won't need to copy the image and so you'll avoid the error.
[UPDATED] OK, so what you'll want to do, based on the comment above, is go in the Finder and remove the existing .icns file from your project (in other words, move it to the Trash). Then you can re-add an icon with the same name (from a location outside your project folder) without getting the error. Also, in the future, remember that you might want to consider using the Also Move to Trash option when deleting files from within Xcode, if you no longer want the unused items inside your project folder.
Also, you may want to double-check to make sure the file in question is included as part of the Active Target. For example, if you add a file to your project, but the "include in active target" checkbox for the file is unchecked (like the ReadMe.rtfd file in the image below), then the file won't be copied into your application bundle at build time or be available at runtime.
(To add that Active Target checkbox column to the Groups & Files list, Control-click on the table column header view and choose Target Membership from the menu).
I want to add a file to an existing folder in Xcode. I have a folder in the file system that I have added to my resources. Now when I add a file to that folder, and try to drag and drop that file onto the folder reference in Xcode, I am out of luck.
Even if I delete the reference and drag the whole folder over again, it does not work, as it imports all files that were in the folder when I originally imported it, but not the new ones.
Any ideas on that one?
Drag it into that folder in Finder, then right click that blue folder in Xcode and then "touch" it. Or collapse and expand that folder icon (is like touching it).
How can i setup my Xcode project so that it creates new class files (.h/.m) in Classes directory and new interface files (.xib/.nib) in Interfaces directory?
By default Xcode adds new files in the root project directory, and i have to manually put these into Classes and Interfaces directories.
Edit:
I'm referring to the Xcode File > New File... option. I want the new files created from the Xcode project to move automatically to corresponding directories e.g. .h/.m files get automatically created in Classes directory, and .xib get automatically created in Interfaces directory etc. And i mean physical directories, not Xcode "Groups".
I assume you've made a group (folder) called Classes, or something along these lines, inside your Xcode project. Select it and do Command+I (or right-click it and select Get Info). Change the "Path" option to the place where you want files to be created.
Please note that it will only affect files you create on it. Creating them elsewhere then moving them to this group will not move them into the directory.
EDIT The above answer applies to Xcode 3. In Xcode 5, you would need to select the logical group in the Project Navigator (first navigator tab, bring it up with ⌘1) and then inspect it with the File Inspector (first utility tab, bring it up with ⌥⌘1). The default physical folder for all the new files can be changed by clicking the folder icon below the Location dropdown menu.
In Xcode 5, it auto-selects the default folder on disk to match to the project folder in the sidebar for certain folders, and it is possible to manually establish this linkage.
In my project, I have sidebar groups for AppName, AppNameTests, and one I created myself called Shared Components. When I select the AppName group in the sidebar and create a class, the Save dialog automatically drills into the AppName subdirectory inside the top-level AppName folder on disk, and does the same for classes created inside AppNameTests.
I was unable to get Xcode to mimic this behaviour with my custom Shared Components sidebar group, despite having a Shared Components folder on disk, but I figured out how to coerce it!
Xcode simply needed to know that the on-disk folder was what my sidebar group was all about. To do that:
Open your project's folder up in the Finder
Drag the folder you'd like linked into the sidebar into the project organizer.
When Xcode presents its "Add Files" dialog, select "Create groups for any added folders". (These are the dialog options I selected:
Now, when I select this sidebar group and create a file, the Save dialog starts in the folder I dragged into the project sidebar. Victory!
Edit: I discovered the keys that Xcode uses in the project.pbxproj file for this: if you change a folder's name key to path, i.e.
path = "Shared Components";
that's basically what Xcode is doing when you add a folder to the project as a group reference. (You can also use both name and path keys if you want the sidebar name to be different than the on-disk path.)