Put files in bundle into specific folder locations on iOS app - ios

The files inside of my app bundle are arranged into folders, but when I check the file layout of the bundle, it seems these files are all added to the same directory, and not sorted by folder as I have them in XCode. How can I make sure they're added to the device in the same folder structure?

The folders created in Xcode using "Group" or "Group from Selection" (yellow folders) are not true Folders, but Groups. They are only a visual way to organize your sources.
To make true folders (blue), create them on disk (using, say, the Finder).
You can then import them into Xcode using the option "Create folder references for any added folders".
In short:
Groups (yellow). Not related to the actual file/folder layout
Folders (blue). Direct representation of the OS hierarchy

Related

xcode create group from physical folder based on file template

I'm currently trying to create a custom file template for xcode. As part of this any new 'file' from my template actually generates a number of files separated into folders better describing their functionality e.g Foo/Presentation/FooViewController.swift, Foo/DataSource/FooDataSource.swift etc. where 'Foo' is the name of the file created.
Although this works and all the files and folders are added to my project, the folders are added as physical folder references. Is there anyway that in a 'file template' these can be converted to groups? Or is there a way to convert a folder to a group in xcode - I've seen lots of questions doing this the other way but not converting a folder to a group.
I could strip all the folders out, but then as this will be used across a team, everyone would have to create the groups themselves everytime, which isn't a very efficient workflow and a template would ensure a common structure.
I can't seem to find any good docs on template creation either and a lot of the sites online seem focussed on older versions of xcode and project templates rather than file templates.
If anyone has any ideas to help solve this it would be appreciated
To convert the folder structure to a group structure, use the following steps once the folders are created in Xcode:
Delete the folder by selecting "Remove References", so not deleting the files and folders, just its reference inside Xcode.
Select the parent folder and then select Files > Add files to "...".
There, add the just removed folder and make sure you select the option "Create groups".
That will add the full structure of folders and subfolders as groups.

Unable to see image files in xcode folder reference

I added a folder which contains some images in Xcode as "Create folder references for any added folders". It added the blue folder but it doesn't show the arrow to see its contents.
Is this an issue in Xcode or am I missing something ?
Screenshot :
Blue folder means you added folder reference ,not folder
Right click on the images folder you added and select show in finder...See if the images are there..if not.. you linked the wrong folder
Make sure the search bar at bottom of the file explorer is empty
You have added the folder in a wrong way. To create a reference folder select the checkbox
'Copy items into destination's group folder if needed'
and in folder options select the radio button
"Create folder references for any added folders".
This works.
If you use blue folder references for your resources these folders will also be created inside your application bundle, while resource files in groups will simply be copied to your mainBundle's root directory.
When folder structure is managed outside of XCode (for example, a cross-platform project which has project files for different versions of XCode, Visual Studio and other IDEs, all using mostly the same directory tree), you normally want folder references. Otherwise one would have to recreate every project file every time folder structure changes.
This is Your solution->
if you do want to auto-import newly added files from the file system's folder to this group in XCode, instead of using "Create groups for any added folders", change to "Create folder references to any added folders"

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.

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.

Moving source files in Xcode 4.2

How can I move source files physically from one folder to another, and tell Xcode 4.2 the new path to those files?
See The Xcode hierarchy is a purely visual organization system. It has no effect on your actual file hierarchy. Xcode leaves the actual file system up to you.
Thus, you could, if you wanted to, have one folder on disk with all your source files, resources, etc. And then, in Xcode, you could have an elaborately organized hierarchy to display your source files.
To get your things done first Make a copy of files in desired directory. Then remove all those files from the Xcode Project. Then add the existing files from new directory and this way you can get Xcode to link to new directory.
Let me know if this helps.
Thanks
Thank you for your solution.
I created aproject X and later on, a view controller with 2 files XViewController.h and XViewController.m inside this project. Those files (by some mistake) were not created inside the physical+xcodevirtual project folder X, but in the root folder that contained X.
When I moved those files from inside Xcode to the X folder, the files seem that they moved there under X and they showed up there in the project hierarchy.
However, this way I ended up with 2 physical copies of them, on at the same level as X physical folder, and another under X.
After adding a property in the XViewController.h and build the project I noticed that my change did not work, and the Xcode reported the error that there was no such property inside the XViewController class and in the .h file.
Using "Show in finder" option I found the real file. Then I copied the updated physical files under X physical folder and delete the files that were in the same directory level as X. That way the Xcode project references to these files became red, implying that the virtual environment had lost the files. So, I completely deleted them from inside Xcode.
Then using File --> "Add Files to X..." menu option I re-connect the "good" physical files to my project X, and this messing problem was solved.

Resources