Objective C unit tests and Categories: 'unrecognized selector'

Published on — Filed under protip

Edit: just found out that -ObjC does the trick as well

Today I ran into this rather annoying issue when running some unit tests on Xcode:

+[Service dateHeaderContent]: unrecognized selector sent to class 0x1004b9280

After spending some time on what I was beginning to think was a wild goose chase, I found out about this little lovely flag: -all_load.

Place it on YourTestTarget > Build Settings > Linking > Other Linker Flags and it’ll fix the aforementioned issue.

Linker flags

If you want to know the "why", read it here.