tags:

views:

53

answers:

1

I've addeda category to NSString. I've tried to place the code in my appDelegate.h and it works. However, I've tried placing it in another .h file that I included from .pch file so that this category can be used project wide. However I kept getting the following error:

ld: duplicate symbol .objc_category_name_NSString_StringTrim in ....AppDelegate.o and .....main.o
collect2: ld returned 1 exit status

The weird thing is, I only get this error when I compile for the simulator but not device! Any ideas?

+3  A: 

I always declare categories in Foo+Category.h and Foo+Category.m, for example NSString+Hashing.h and NSString+Hashing.m. In the source that uses the category I then import the Foo+Category.h and everything works wonders. The good thing about this solution is that the category gets mentioned explicitly in the code that uses it, so that the magic is apparent.

zoul
I typically go with "FooAdditions.h" but I'm liking your way. Consider me converted.
Nick Veys