Handling duplicate filenames in Xcode - ios

I'm writing an iOS project in Xcode 4 that uses several third-party libraries. One of those libraries contains a file with the same name as a file in my project. I'd like to put both files in separate groups, but it seems like Xcode only allows one instance of each filename in the entire project.
Is there a way around this other than renaming one of the files?
Edit: The files are Objective-C source files (.h and .m). I'm not familiar with mapping groups to folders. How do I tell Xcode to make my groups separate folders on disk?

You can directly Drag & Drop a folder onto the Xcode project and then select Create Folder references for any added.... I don't think you can directly create folders through Xcode. You can however add a Build Phase for copying files which will allow you to create folders in your bundle.

Related

Export files from Xcode project

I currently have an Xcode workspace with an app project and the pod project (as commonly happens). I would like to "export" some of the files containing classes and structs that would be preparatory for a new project that should begin soon. These files are totally separate from each other and should not be exported as a library or framework because that should require to keep everything updated. Instead, I would rather bring these files out of the app project, but keep them into the workspace. Is it possibile? If so, how can I achieve this goal?
When you want to keep your common code and be able to maintain it as one code on both projects then I suggest you still use a framework. It is hard to tell from your question what you mean by "because that should require to keep everything updated" but using a framework within your workspace works awesomely in Xcode and any change you do within framework is instantly reflected in your code. So no extra deployment work is needed at all. To do so you simply do the following:
Create a new project selecting Framework
When creating the project select your workspace from dropdown menu (it is at step where you select project folder location)
In Xcode file navigator in newly created framework project open "Products" directory which should contain (in red) FrameworkName.framework
Open your main project target settings and open General, scroll down to Frameworks, Libraries... and drag that .framework file in this list
That is all. Now you can use your framework in your code. Simply import it in any Swift file you want to.
If at this point you are worried that you need to add import MyFramework into each and every Swift file where you use it then there is a shortcut. You can simply add a new Swift file and use type aliases to avoid this problem:
import MyFramework
typealias Class1 = MyFramework.Class1
typealias Class2 = MyFramework.Class2
typealias Class3 = MyFramework.Class3
Not the cleanest solution but it does the job.
On the other hand if you wish to extract files and use them in a new project but not share the code. So then each of the projects may eventually end up with different implementations of these files then you need to duplicate the files. You can do that easiest with file system by copying source files themselves.
You can then put them into workspace under whatever you want. If you wish that currently none of the projects contain these files you may simply select files in Xcode and uncheck Target Membership for all projects on file settings.

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.

How can I arrange my project files according to their folder structure in Xcode

I am working on a MASSIVE project with about 10 thousand files in it. The files are nicely arranged in Xcode's directory system but not so on the disk. Is there a tool that I could use that would make the folder structure on my disk represent the folder structure in Xcode?
Personally, I know two ways to do it:
Do it manually (rearrange your folder first, and then drag and drop your directories in xcode). That will do the job.
Use an external library, I suggest you synx. It does the job well
I don't know why you want to do that, but I don't think it's really important if your folder isn't ordering with your xcodeproj since you will always open it with xcode. Just separate assets is enough, isn't it?

Including submodule .xcdatamodeld file in project

I am currently building multiple applications that all share the same CoreData stack. This includes models, network requests, etc. Basically all of the business logic is held in this repository (let's call it DataKit). The DataKit project generates a static library called DataKit.a
Now I have two apps, App A and App B. Both of them need to include the .xcdatamodeld in DataKit. How I have done this in the past, is to copy the .xcdatamodeld file from DataKit and put it into the App A or App B project. This is really ugly and I am trying to figure out a cleaner way to include the .xcdatamodeld file without having to copy it into the App project.
I've tried adding the .xcdatamodeld file to a Copy Files phase in the Build Phases for DataModel.a but it didn't work.
Anyone have any suggestions/tips?
The .xcdatamodeld file is an abstract representation of the managed object model that is compiled into a .momd file. The .momd file is what Core Data opens. For your projects, you would need to either have the .xcdatamodeld in the Compile Sources phase, or the .momd file in the Copy Files phase of the target that is dependent on the library. Obviously, this is pretty cumbersome when attempting to distribute code as a library. Frameworks allow you to include resources (such as momd files), and are in general much more flexible than libraries. iOS 8 allows dynamic frameworks, previous versions of iOS allow static frameworks even if the tools do not exactly support it.
You could include a method in your framework that returns the correct data model. It is not necessary to be stored in the bundle as a separate file / directory.

Textmate and add existing files

I don't understand why when I add files to my project using add existing files from project try it does not copy the file to my project, it just copies the reference to the file.
In TextMate, a project is nothing more than a collection of references to files you can edit simultaneously. It enables you to have them open in a drawer and as tabs as you will most certainly know already. But a TextMate project is not intended to be a file manager. More information on handling files inside a project can be found at the TextMate manual.
Add the folder to your project drawer on the left then you will be able to drag the files from there into your Rails project.
I was running to the same problem with trying to add existing files to a folder in my project, it would not change the reference.

Resources