0

I made a class that uses the delegate pattern and I put it in a static library. Then, I created a demo app to test the library. The demo just has a single view controller, and in the .h file, I have this:

@interface ViewController : UIViewController <AuthenticationDelegate>

@property (nonatomic, retain) IBOutlet UITextField *usernameTextField;
@property (nonatomic, retain) IBOutlet UITextField *passwordTextField;

@end

When I compile, I get an error right on the first line of the file that says:

Cannot find protocol declaration for 'AuthenticationDelegate'.

But, in the .m file for the same view controller, I have:

#import "Authentication.h"
#import "ViewController.h"

The file "Authentication.h" is the only header file in my static library, and it does declare the delegate class:

@class AuthenticationProvider;
@protocol AuthenticationDelegate <NSObject>

@optional

- (void)provider:(AuthenticationProvider *)provider didReplyWithResponse:(AuthenticationProviderResponse)response;

@end

Where am I going wrong?

Update:

If I put #import "Authentication.h in ViewController.h, I get this:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_AuthenticationProvider", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I get that when I remove #import "Authentication.h from ViewController.m also.

woz
  • 10,888
  • 3
  • 34
  • 64

1 Answers1

1

Try #import "Authentication.h" in your classes .h file, not your .m file

nielsbot
  • 15,922
  • 4
  • 48
  • 73
  • I tried that, but I get the error that I just updated my question with. – woz Jul 12 '12 at 18:17
  • ok that's progress--now it's an error at the link stage, not the compile stage.. looks like your static library isn't being linked in. Add it to your "Link Binary With Libraries" build phase. – nielsbot Jul 12 '12 at 18:19
  • Ok, great! I think it's close. I have another error, though, which is probably unrelated. When I compile, I get: `ld: warning: ignoring file .../Authentication Demo/Authentication Demo/libAuthentication.a, file was built for archive which is not the architecture being linked (i386)`. I am working on that right now, but no luck so far. – woz Jul 12 '12 at 18:34
  • Did you build the static library yourself? You'll need to build it with the right CPU architecture for your current project. You can't link an x86_64 (64-bit) binary with an i386 (32-bit) binrary, for example. – nielsbot Jul 12 '12 at 18:39
  • Ok, I had to use to fix that other error: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4. I got it though. Thanks! – woz Jul 12 '12 at 19:20