XCode: Where to put image resources - ios

I'm trying to add some App Icons and Launch Images for my App. My code-files are organized in groups inside Xcode and the same in the File System. I tried to drag a folder named Resources with my PNG images into my App and afterwards trying to add them as the App Icons and Launch Images for my App, but Xcode then gave me an warning and copied the file to the root of my project -- both in Xcode and File System.
Is it normal, that the Image are put in the root (in same level as the xcodeproj file)?

Yes it's OK. What can I suggest you is not to worry about filesystem and organize your files/directories within the project.
It's same as with iTunes: you don't care what and where your files are, but you have a nice interface to work with them.

Related

Why does xcode ignore a symbolically linked app icon in the asset catalog source?

I have the following structure in my iOS Project source folder:
resources:
ios/ mac/
resources/ios:
Images.xcassets/ Info.plist LaunchScreen.storyboard
resources/ios/Images.xcassets:
Contents.json LaunchImage.launchimage/ AppIcon.appiconset/
Everything works fine. If I replace the directory AppIcon.appiconset with a symbolic link to a directory with the exact same content, then when I open Images.xcassets in Xcode it shows only LaunchImage and I get a build error that no icon named AppIcon could be found.
This appears to be an Xcode issue. Is it a bug or by design? If the latter, is there a way around it? I really don't want to have multiple copies of these images in the sources for multiple apps.
I can't use hard links because the code is in a git repo so anything other than the original repo would end up with multiple copies on checkout.
If Xcode refuses to copy resources from symbolic, there is probably no way to do this. However, if you want to strictly keep the icons synchronized, you can use a custom shell script phase in your project, which copies the image assets from the macOS folder to the iOS folder.
Just another, even simpler solution could separation the images into special and common icons, and sharing the complete 'common' asset catalog in both targets.
You can create AppIcon.appiconset as a regular directory and put symlinks inside to each of the shared Contents.json and png files. This requires more symlinks but does centralize the image storage.

Can you put iOS icon & launch images in a different directory to the project root?

I have a cross-platform codebase, structured a bit like this:
/Projects
/App1
/src
/iOS
/App2
/src
/iOS
/App3
/src
/iOS
Win32.sln
iOS.xcodeproj
XCode wants to put icons and launch images under /Projects, as siblings of the .xcodeproj file, but that's messy - these are project/target-specific files. I would rather have each app keep app-specific iOS files under e.g. App2/iOS.
I've seen some topics on this kind of issue, talking about how xcode wants to copy images to the root, but no definitive answer if you can or can't do it.
edit: the same goes for my app .plist file, can I relocate this?
Currently the project I'm working on has the load screen icon in root folder and the appIcons under Resources/Icons so there's definitely a way of copying them there.
Try copying the icons to the desired folder manually, then add them to your project and uncheck "Copy items into destination group folder".
Also, I would advise you to create folders using finder, then adding them into Xcode to use them as Groups instead of creating them in Xcode.
I have found these are all possible
The plist file is easiest, there is a build setting info.plist which must be updated accordingly.
For the icon and launch images, remove references from your project and then move the files on disc to some folder that makes sense for your codebase. Then add these items to the project (right-click, "add files to "). Finally, use a copy files build phase to copy them to the Resource folder, or possibly add them to a Copy Resource Bundle build phase.
When I did this, the files were copied into the App-Bundle itself, the iPad displayed them as expected, and XCode displayed the images in the Project Summary screen.

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.

Xcode: Multiple directories and subdirectories

I'm trying to figure out how to get all of my map tiles into XCode, so that I can call them like:
/0/0/0.png
/1/0/1.png
... etc
Hasn't seemed to work so far, so I was wondering if anyone could advise on how to do so.
When adding resources to Xcode, if you select "create folder references for any added folder", then Xcode will preserve hierarchic structure when copying these folders to bundle. Referenced folders have blue folder icons in project navigator.
A downside to this approach is that Xcode doesn't watch changes of files in referenced folders, so if you change an already added file, you'll have to do a clean build or the app bundle will have an old version of the file.
When you build your XCode project, all resources are copied directly to your application's bundle, so if you have several images named the same (even if they are in different directories), only one will be taken and the rest will be ignored / overwritten.
If you have something like 0/0/0.png, 1/0/0.png I'm sorry for what I have to tell you, but you will have to rename your tiles to something like 000.png, 100.png and so on.
Also, to get an image that you added in your project, you get it by name, like this:
UIImage *tileImage = [UIImage imageNamed:#"000.png"];

Xcode - is it ok if I made a group for my image files and they are not at the base of the project?

I am reading the instructions here for the correct file setup for submitting the app to the app store: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html
in there there is a phrase like: "Like all other icon files, the iTunesArtwork image file must reside at the top level of your app bundle. "
But for organization sake, I made a group, and placed all the image files in root/src/img group. Is that ok? Or should I specifically move all the image files to the root or the project?
Thanks!
What you're doing is OK. When you place resources into a group, Xcode will copy them all into the root of your application when it builds it.

Resources