Modifying the default -Prefix.pch file - ios

I would like to know how I can modify the default .pch file included with the xcode project templates.
I would like to do that in order to have a few #defines automatically included in all my projects. An example of what I would want to have for all my projects is something like the following for a shared app delegate:
#define APP_DELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate])
I tried searching for a template .pch file within xcode's package with no luck.
If you think it is not a good idea to do this, feel free to tell me why, but please also tell me how I can modify the template if you can, since that is my question.

The default Xcode templates live in /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates . Inside Base/Base.xctemplate you will find a file TemplateInfo.plist . That is what you will have to modify to do what you want. Look at the Definitions section of that plist.
If you want to do this only for iOS, you will instead need to modify the templates in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates. The structure of the iPhone Base.xctemplate though would not make changing the default prefix header for iOS only easy though.
XCode templates were once straightforward to use and create, since XCode 4 this has not been the case.
I would strongly suggest following some of the information online about creating your own templates instead of modifying those inside Xcode.
This is one of the best starting points for creating your own templates and learning how templates work

Related

JUCE iOS build has no target

I have code for a VST plugin and need to port some of it to an iOS app.
I have tried building the OSX version and using the lib.a and it doesnt work. When I open the iOS version of it, Xcode shows that it is missing the tagret.
If I copy the code directly into Xcode with all the JUCE modules, and I set the header search paths, I get compilation errors on things like no such type for String
After this latest JUCE update, Xcode would give the same errors until I updated the JUCE file itself, so I think the JUCE build settings or configuration of the new version is doing something differently. How can I get this code into a different Xcode project, so that I can use it?
Can I compile it as a library and use the objects through the header?
JUCE is designed to be included in projects generated by the Introjucer / Projucer (the JUCE project management tool). Without this, the correct preprocessor definitions will not be set up.
If you really needed to include JUCE source code inside your program, you could manually set up these preprocessor definitions (take a look at the AppConfig.h header from a generated project to get an idea of how much work this will be), but you'd really be going against the normal "JUCE way".
Simply including the headers and linking against the library will not work without considerable effort, as the include structure is ... odd ... and there isn't any library to link against directly anyway (the generated projects contain all the JUCE source normally, so there's no need).
Adding the JUCE source files (i.e. .cpp and .mm) to be compiled in a project directly will result in compilation errors, as they need to be compiled in a very specific order which is mandated by the header file (the header files #include certain implementation files after setting up their dependencies).
In short, if you can at all I would advise generating the project with the Projucer and adding other source files in as you need them, rather than the other way around.

Referring to an .h class of a subproject

the Dropbox iOS SDK has its own Framework bundle but in order to customize it easily I ve chosen to include its Xcode project as a subproject.
How should i refer to its .h classes?
I ve added the .xcodeproj from the "Add files" button and I ve added in the Header Search Path the following value:
$(PROJECT_DIR)
The subproject looks to be at the same level with the main project.
Shouldn't the importing itself link the dependencies?
(I m really frustrated by the import system in Xcode)
Your basic approach seems sound (and is pretty close to how I handle lots of vendor projects). Since you've added $(PROJECT_DIR) to your header search path, and assuming that the framework is in a directory named "Dropbox", then you can refer to the packages a couple of ways:
#import <Dropbox/Header.h>
#import "Dropbox/Header.h"
I prefer to think of the sub-projects as "system-like" and so tend to use angle-brackets, reserving double-quotes for internal code. But either approach is really fine.
Shouldn't the importing itself link the dependencies?
No. You still need to link the dependencies. #import does just exactly one thing: inserts the requested file into the current file. That's all it does. It is identical to you taking the referenced file and copy/pasting it into your code (that's basically how it's implemented in the pre-processor). That this is used for "header" files is a matter of convention. It has nothing to do with how the compiler works. You technically could import a .m file that included a method in it as a way to do code reuse. (I've seen that done in projects I've worked on. Please don't do this....)
When dealing with ObjC modules, it's a little different (using #import rather than #import). But if you're just importing headers as you seem to be, think of it as "stick this other file right here, exactly as written."

Does XCode have something similar to properties files in Visual Studio

Background
I'm porting a small Windows application to iOS using XCode 6.2 as both the IDE and build platform. I have a workspace created, which I'm using to compile and build all the projects. I currently build every project except the actual iOS app as a dynamic library, and then embed it in the final app package on deployment.
The Problem
I'm currently hard coding relative paths in the projects. Stuff like ../../shared-headers - I really don't like doing this as I have to figure out this path per project, and I'd prefer to use something like props files in Visual Studio, which would let me do something like $(SHARED_HEADERS) in projects.
This makes the projects easier to maintain, and any dependency extremely obvious. It also makes it much easier to move projects when the need arises. What is the preferred method to do this in XCode?
EDIT: I'd like to stick with a Visual Studio-ish include structure. While Copying headers is a good way to manage some of the complexity, I do not prefer this method because it will add time to the build, and developers from Windows will not be expecting this.
I too was looking for the same thing, and i've just found it! using an xcconfig file!
Create a .xcconfig file either from xcode's file menu or just a simple text file, and add your entires like so:
PATH_TO_SOME_SDK = Volumes/DEV/Project
SOME_DEFINITION = 7
once you add that file to the project, you can add it (or different ones) to each configuration in the project's info panel under "Configuration".
the definitions along with their values will then appear in the project's build settings under "User-Defined", and will change dynamically as the value in the file changes.
you can then use the values in any other build setting like any other environment variable or macro:
$(PATH_TO_SOME_SDK)
for more info:
https://nshipster.com/xcconfig
https://medium.com/better-programming/working-with-xcode-configuration-files-398cfbe02b64
https://help.apple.com/xcode/#/dev745c5c974
better late than never...
:-)

How to create a custom Swift File template for Xcode 6?

I'd like to make a couple of Swift file templates that I can drop into Xcode's file template picker. I know how to make a custom Playground template and Obj-C file templates but for Swift there seems to be no file template available at all in the following path:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/
This surely should be possible, shouldn't it? (Or does every app developer start with the awful default templates?)
I've created a new template folder under the path
/Users/name/Library/Developer/Xcode/Templates/File Templates/User Templates
with the name Swift File.xctemplate and the following contents:
___FILEBASENAME___.swift
TemplateIcon.png
TemplateIcon#2x.png
TemplateInfo.plist
and of course edited the files accordingly. When I open Xcode's temple chooser, my template appears but it somehow doesn't work correctly. It also opens a file browser and asks where to store the file which isn't right, and the file doesn't appear in the project afterwards.
Is there any solution to this? The web seems to be devoid of such information.
Using Xcode Version 6.1.1 (6A2008a), if you go into one of the template bundles found in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source you'll see the swift templates.
So, for example, let's open up a new Terminal window and look inside the Cocoa Touch Class.xctemplate bundle to see all the swift templates:
$ cd "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/Cocoa Touch Class.xctemplate"
$ ls *Swift
NSObjectSwift:
___FILEBASENAME___.swift
...
That should give you a good place to start looking so you can figure out what has gone wrong with your custom template.
A couple things that always help me are:
1) Check, double check, and triple check your TemplateInfo.plist file, it's the most important file in the template and the easiest to mess up.
2) Sometimes, when I can't get Xcode to recognize my new template, or changes to an existing template, then restarting the dang thing sometimes works wonders.

XCode - iOS - <OCMock/OCMock.h> file not found

I Have an iOS application that I am trying to add OCMock to in order to better unit test it. I've followed the instruction on ocmock.org as well as instructions I've found in other places but still I cannot get my test code to compile.
Here's what I've done
Added the source code to my project directory
Create the groups in my project to mimic my file system
I selected the option to add to my test targets so the framework was added appropriately as well as the Library Search Path
Then I manually added the headers to the Header Search Path
And added the -ObjC linker flag
Then when I go to import the header file, I get the file not found error
Any ideas what I am missing here???
You have the search path test/libraries/OCMock. Then you have #import <OCMock/OCMock.h>.
This fails because there is no file test/libraries/OCMock/OCMock/OCMock.h.
You use the search path test/libraries, or you can create a prefix directory to hold OCMock and have the search path point at that.
I generally have a directory with the library name and version number before the actually directory.
The directory test/libraries/OCMock-X.X.X could contain the OCMock directory. That way the search path still be more specific: test/libraries/OCMock-X.X.X and you still use OCMock/OCMock.h as the include.
One more thing to check, for anyone else having this problem - I copied OCMock from one project to another and everything looked right, but it wasn't finding the include file. It turned out that even though I had the right groups in Xcode, the files had all been dumped into one directory. I needed to create folders on disk and associate them with the groups in Xcode. The accepted answer here clued me in to what was wrong (though as is often the case, in hindsight it should have been obvious).

Resources