Xcode copies images everytime I compile my project. - ios

Whenever I build my current iPhone project, it copies every single picture I've added to the project into a new resources folder.
I didn't realize this until today but now I have a resource folder thats 1GB full of the same photos that have been copied over and over again.
When I build it says: Copying xAmount of xAmount resources to product
Is there anyway for me to turn this off so it only copies new images that have been added?
Thanks.

when you import resource files on your project, be sure to have: "copy items into destination group's folder if needed" option checked.

Related

Resources not copied to bundle

I have an XCode project for an iOS application, and added to it 3 small mp3's in the structure that are copied to the destination bundle upon compilation.
I have then added a bigger mp3's (4MB) to the structure (same folder than the previous ones) and into the Build Phases:
However upon compilation, this file is not present in the bundle. I tried to clean and recompile, change destination, but the file is still absent:
Anything I could have forgotten to check ?Thanks.
Go to your build phase->resources and check these files are showing there or not and check when you add them did you allow them to copy when required checkbox was selected or not.
When you add resources, make sure not only the copy items into destination group's folder (if needed) is ticked, but also tick the corresponding target in the Add to targets list.

Accidentally removed xcassets file from Xcode project

I wanted to remove a single folder from the image collection, however, I somehow managed to throw the entire xcassets file into the trash.
The normal 'Put back' method is not available, and simply dragging the deleted folder to Xcode yields an error:
"Images.xcassets" couldn't be copied to "ProjectPear" because an item with the same name already exists.
To save the file, either provide a different name, or move aside or
delete the existing file, and try again.
I'm not sure where this collection is located within my Xcode project, as the navigator doesn't appear to show anything, and the command-line isn't dropping any hints either. I'm afraid to mess around with the project.pbxproj file, as it might jumble up a lot more than just my image collection.
Edit:
Dragging the files back to Finder from Trash was successful, however, the Xcode navigator no longer recognises - or in this case, still doesn't recognise - the .xcassets file. I'm not sure whether to add something in the .pbxproj file.
I just did this myself and figured out how to quickly remedy the issue.
Go to the project folder in the Finder. You should find that the
folder Images.xcassets is still there.
Move it to a separate location like to the Desktop or something. It
still has all of the images and json files.
Jump back to Xcode and create a new asset catalog for images.
File > New > File... > Resource > Asset Catalog
Name it Images.
Quit Xcode and return to the Finder.
Copy the folders from within your old Images.xcassets to the new
Images.xcassets directory in your project.
Launch Xcode and you're back in business!
If you didn't delete it completely, you can just drag it back in from Finder. (Right click your project and select 'Reveal in Finder' to check)
If it's gone completely you simply go Cmd+N -> Resource and select Asset Catalog. You then re-add your imagages via drag and drop or right-click and 'Add Files to ...' and should be good to go.
Hope that helps.
Usually the file's reference is removed from Xcode, the original folder still exists in the project directory.
Right-click on your project folder, click "Add files to "your project"", find Assets in your project and click Add and you're
done
Had the same problem today with Xcode Beta, I also couldn't create a new assets catalog for some reason.
This was on a Watchkit Extension Project
Here's what I did to solve it:
In finder I copied an existing images.xcassets from another folder in my app to my desktop.
Removed the content of this folder.
Copied a deleted (single) Image Asset from my trash into the folder (on my desktop).
Dragged the entire folder into my project in XCode.
That fixed it and everything went back to normal.
If you have deleted it completely, then also these are the steps to get a new Images.xcassets:
In the Navigator, click on the project.
Go to : File>New>File> Add Asset Catalog> Name it.
To add AppIcon and LaunchImage in it:
Go to the Project Setting:
In General Tab, Slide down to App Icons and Launch Images
Click option next to App Icons Source and select Use Asset Catalogs
A window will pop up- select the name of your new Images.xcassets file and click on Migrate.
Select Also add LaunchImage. Now you can see the new Images.xcassets in your project :).
I accidentally deleted the reference to the asset folder so that it was no longer visible in Xcode. But when I checked from the finder, the asset folder was still in the project folder.
If you did that, just open the file menu in Xcode (from within your current project) and at the very top you can add (existing) files to that very project (back again) - it says "Add files to..."
Right click on anything in your project and click "Show in Finder". Search around in your project folder in the finder for a bit and you'll find it. I'm not on a Mac right now, or I'd give you a more direct path straight to the default .xcassets folder location.
And anyway, if you're not able to copy/create a "new" folder in that location because "an item with the same name already exists", then that means you didn't actually delete the folder. You just deleted your project's references to that folder in XCode. The folder on your hard drive didn't go anywhere.
[I realize this is a very old question from you #Aeveus]
All the answers talk about re-doing the adding assets again. Given you could not undo, the one step that is missing in your original description is this:
In your project.pbxproj file, there would have been references to assets as below:
45AE4E781C183FBA0051674F /* Assets.xcassets in Resources */ = {...
Assuming you have source code control system (git, etc) you can revert to the original contents of your project.pbxproj file, or manually just re-add the deleted lines, and re-open the project file in xcode. You are all set now.
I had the same problem. Open your XCode Project. Just go to File -> Add Files to...(your Project) -> Assets.xcassets and you are good to go!
I had same problem and I have followed the steps above from Jason, but finally i got Image.xassets in red color, so the in order to find my images I had to click in Image.xassets and then on the top right corner put the absolute path to my image.xassets folder and it fixed my problem.
Hope it helps!

Xamarin studio folder structure issue in iOS project

I am having trouble with xamarin folders. Currently I'm writing xamarin iOS project. In Xcode I used directories for grouping images, there could be several levels of nested folders, but when I was building project for device or iOS simulator, these resources where simply being copied to main bundle, without any folder structure. I can't reach the same behaviour in xamarin studio. Whenever I create folders in my project and put pictures or other resources in them, this folder structure is recreated on the actual device, and thus, I struggle against different paths, when loading images. How can I make xamarin studio simply copy the files in the folders to main bundle, instead of recreating folder structure?
Thanks for help.
My first suggestion is to change the BuildAction property of your images to BundleResource.
Once you do that, there are multiple ways of achieving your goal:
The first option is to specify a LogicalName to be whatever you want the name to be inside of the compiled app bundle. Currently there's no way to set the Resource ID (UI name for the LogicalName property) for anything other than EmbeddedResource files (I'll work on fixing that momentarily), but you can edit the *.csproj like so:
<BundleResource Include="Icons\icon.png">
<LogicalName>icon.png</LogicalName>
</BundleResource>
Normally, that Icons\icon.png file would be copied into the iOS app bundle as Icons/icon.png, however, the LogicalName property overrides the relative path name. In this case it would be copied over as simply icon.png.
As another example, you can also do this:
<BundleResource Include="Icons\iOS\icon.png">
<LogicalName>AppIcon.png</LogicalName>
</BundleResource>
This will copy the Icons\iOS\icon.png file into the root of the iOS app bundle and also rename it to AppIcon.png.
A second option is to simply move your image file(s) into the Resources folder. The Resources folder is special directory that get stripped out of the default path names when copied over to the iOS app bundle. In other words, Resources\icon.png would be copied over into the root of the iOS app bundle as icon.png rather than Resources\icon.png as is the case with normal project directories.
A third option is to simply register other "Resource" directories of your own (and they can exist within other directories, including the default Resources directory).
For example, you could have the structure in your project:
Resources/
Icons/
icon.png
icon#2x.png
And in your *.csproj file, edit the following tag:
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
and replace it with:
<IPhoneResourcePrefix>Resources;Resources\Icons</IPhoneResourcePrefix>
This will ensure that the icon.png and icon#2x.png files are installed in the root of the iOS app bundle.
Xamarin has two ways to setup files you want present in the iOS bundle:
Put them in any folder, and mark the "Build Action" as "Content". Whatever directory structure you have in your project will be present in the main bundle.
Put them in the "Resources" folder, with a "Build Action" as "BundleResource", this does the same as #1, but removes the "Resources" folder from the path present in the bundle. This is a nice place to put all images you want in the root of your bundle but would clutter up your project.

move an xcode 4.5.1 project to different folder

I have created a rather large application in xcode and wish to move the files somewhere else on my computer.
Could this process be as simple as dragging the project folder to a different place in finder or will something mess up?
Moving the .xcodeproj files will not cause any issues as long as xcode is closed when you migrate the files and you delete the old files.
When xcode is next launched, if you browse and open the proj file from the new directory, all the references will be set to the correct destinations
on a side note it always pays to keep the old files in a .old folder when migrating projects to avoid issues.
As long as the files are kept in their respective folders, next time you run a build in xcode, the references to the new directory the proj file is in will be updated.
As another side note, i just tried to do this and it messed up for me. Typically, any references will switch over, but i had a linker error: ld. it was trying to link to an external library that was contained within the old folder. i had to go to build settings->search paths->library search paths and change that to the new folder location. that worked for me.

File in folder that added using "Create folder references for any added folders" not updated

I need to make a folder in app bundle to manage my resources file, images, sounds, etc. So I add my resources folder to xcode using "Create folder references for any added folders".
Problem
I got a problem when I want to update file in this folder (add file, rename, add sub folder), after I build it (both simulator and device) the folder didn't update to reflect my change, I have to Product > Clean to make it update. I wonder if I ship my product this will cause the problem or not, force user to reinstall my app every time I update my resources won't be a good thing to do.
The resource files will be effectively copied in to your application bundle at compile time. If it is working after clean, and you see it working well on your phone, the same way the correct files will be copied to the application bundle when you Archive the App before submission. So I would not worry about this until you are sure to make a Clean also before Archiving at the time of submission.

Resources