Modifying the default -Prefix.pch file

603 views
Skip to first unread message

Decoder

unread,
Aug 25, 2013, 12:55:58 PM8/25/13
to cocoa-...@googlegroups.com
I would like to know how I can modify the default .pch file included with the xcode project templates.

Example: to add below #define in default pch file-

#define APP_DELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate])

I tried searching for a template .pch file within xcode's package with no luck.


Please suggest.

Charlie

unread,
Aug 26, 2013, 2:53:20 AM8/26/13
to cocoa-...@googlegroups.com
The prefix header file is usually in the Supporting Files or Other Sources folder within the project navigator. If you were searching using the search function to search for it, then of course - it doesn't look at the file names. See the little search field at the bottom of the file list in the project navigator and enter "pch".

Devarshi Kulshreshtha

unread,
Aug 26, 2013, 4:50:34 AM8/26/13
to cocoa-...@googlegroups.com
I want to modify the .pch file.. which is created by default in an XCode project template.. my problem is similar to this:



--
You received this message because you are subscribed to the Google Groups "cocoa-unbound" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoa-unboun...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Thanks,

Devarshi

Mikael Konradsson

unread,
Aug 27, 2013, 2:21:55 AM8/27/13
to cocoa-...@googlegroups.com
Hello!
I understand what you like to accomplish, but not why? 
Why can't you create a class method for this instead?

+ (id)appDelegate {
return [[UIApplication sharedApplication] delegate];
}

//-----------------------------
id myAppDelegate = [MyApplication appDelegate];

Regards!
//Mikael

Charlie

unread,
Aug 27, 2013, 3:26:34 AM8/27/13
to cocoa-...@googlegroups.com
Decoder: Sorry for the misunderstanding, I missed the word "default". Unfortunately, messing with the default templates is a temporary thing since mostly each update will overwrite your changes, so be careful and have your modifications backed up somewhere. Not sure what happens to your own templates.

Konrad: Modifying the prefix header file allows you to use stuff anywhere in your project without explicitly importing it. So if you use the AppDelegate in every other class you write, it may be a good idea to add the import to the prefix header file, so that you don't litter your code files with imports. Declaring a macro for a faster access is generally why the macros are there ;)

Mikael Konradsson

unread,
Aug 27, 2013, 3:46:53 AM8/27/13
to cocoa-...@googlegroups.com
Hello again!
You should be able to import your header (your app MyApplication-Prefix.pch) to "appname-Prefix.pch" so you won't need to import elsewhere.
//Mikael

Devarshi Kulshreshtha

unread,
Aug 27, 2013, 4:49:09 AM8/27/13
to cocoa-...@googlegroups.com
Thnx all for your useful replies.. :-)

Konradsson: I understood the approach suggested by you.. but still if I want to modify the default pch file, is there any way to do so?

mare

unread,
Aug 25, 2013, 2:01:22 PM8/25/13
to cocoa-...@googlegroups.com
It's here (for iOS):

Xcode5-DP5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/Cocoa Touch Application.xctemplate

Here's an article how to adapt templates:


HTH
-- 
mare

Mark Miller

unread,
Aug 27, 2013, 9:56:00 PM8/27/13
to cocoa-...@googlegroups.com
Do not do this.  Not only will this break for every Xcode update it is terrible design.  A very reasonable and appropriate answer was provided to you by Mikael:


Why can't you create a class method for this instead?

+ (id)appDelegate {
return [[UIApplication sharedApplication] delegate];
}

//-----------------------------
id myAppDelegate = [MyApplication appDelegate];


Charlie wrote:

Declaring a macro for a faster access is generally why the macros are there ;)

If this is your approach to programming, then you are going to have a hard time.

I strongly suggest you take a look at the "Cocoa Design Patterns" book and learn from it.



--
You received this message because you are subscribed to the Google Groups "cocoa-unbound" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoa-unboun...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
mark miller
him...@gmail.com
Reply all
Reply to author
Forward
0 new messages