1

Steps to reproduce:

Create a new Xcode Workspace (WorkspaceTest).

Create a single-view project called "One".

In the workspace (not the project), create a Group called "Shared". In that folder create a category called UIColor+Hex:

.h:

@interface UIColor (Hex)

+ (UIColor *)colorWithHexString:(NSString*)hexString;

@end

.m:

@implementation UIColor (Hex)


+ (UIColor *)colorWithHexString:(NSString *)hexString {
   //implementation here
}

@end

Go to the "One" Target Build Settings and add this for Header Search Paths:

/Users/me/iOS/test/WorkspaceTest/Shared

Go to the default ViewController.h and add this:

#import "UIColor+Hex.h"

- (void)viewDidLoad {
    [super viewDidLoad];        
    self.view.backgroundColor = [UIColor colorWithHexString:@"ff0000"];
}

The project compiles fine, which means it found UIColor+Hex.h.

However when it runs I get this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIColor colorWithHexString:]: unrecognized selector sent to class 0x107db8c60

This method is present in the UIColor+Hex.m file. What else do I need to do?

soleil
  • 12,133
  • 33
  • 112
  • 183
  • Is the .m file being built and included in your app? – Hot Licks Oct 18 '14 at 00:23
  • Um, apparently not. The question is how to include it. – soleil Oct 18 '14 at 00:24
  • I forget the details (been awhile since I did this, and don't have a mac at hand), but basically RMB on the file, select it's properties, and check your project in the list of build targets. – Hot Licks Oct 18 '14 at 00:25
  • That's if the file is already in the Project. This is the case of a shared group of files that does not belong to any single project. Like I said above, it's created in the workspace, not in the project. I want it to be available to all projects in the Workspace. There's no "Target Membership" option for files that are not in a project. – soleil Oct 18 '14 at 00:31
  • You've got to add it to the project. I can't tell you the details. (No, maybe I can. Add a "Shared" folder to the left-hand file list, RMB on that, and select "Add files" or some such.) – Hot Licks Oct 18 '14 at 01:44
  • The point is to make a set of files that are shared between all projects in the workspace. Like a static library, but without the pain of creating and maintaining a static library. – soleil Oct 18 '14 at 05:27
  • I'm pretty sure you can add a file without physically moving it into the project directories. Otherwise you need something like CocoaPods, but that's taking on some of that "pain". – Hot Licks Oct 18 '14 at 11:49

0 Answers0