2012-07-12 62 views
0

我做了一個使用委託模式的類,並將其放入靜態庫中。然後,我創建了一個演示應用程序來測試庫。演示只是有一個單一的視圖控制器,並在.h文件中,我有這樣的:代表靜態庫中Xcode不工作

@interface ViewController : UIViewController <AuthenticationDelegate> 

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

@end 

當我編譯,我得到該文件的第一行一個錯誤,指出正確的:

Cannot find protocol declaration for 'AuthenticationDelegate'.

但是,對於同一視圖控制器.m文件,我有:

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

文件「Authentication.h」是我的靜態庫的唯一的頭文件,它也宣佈委託類:

@class AuthenticationProvider; 
@protocol AuthenticationDelegate <NSObject> 

@optional 

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

@end 

我哪裏錯了?

更新:

如果我把#import "Authentication.h在ViewController.h,我得到這個:

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) 

我得到的,當我從ViewController.m刪除#import "Authentication.h也。

+0

如果您引用AuthenticationDelegate在視圖控制器頭文件試試#import "Authentication.h",你需要把進口存在。 – jtomschroeder 2012-07-12 18:13:57

+0

@ j.tom.schroeder我試過,但我得到了錯誤,我更新我的問題。 – woz 2012-07-12 18:18:29

回答

1

類中的.h文件中,而不是你.m文件

+0

我試過了,但是我收到錯誤,我剛更新了我的問題。 – woz 2012-07-12 18:17:35

+0

好吧,這是進步 - 現在這是一個鏈接階段的錯誤,而不是編譯階段..看起來像你的靜態庫沒有被鏈接。將它添加到你的「鏈接二進制庫」構建階段。 – nielsbot 2012-07-12 18:19:41

+0

好的,太棒了!我認爲它很接近。但我還有另一個錯誤,這可能與此無關。當我編譯時,我得到:'ld:warning:忽略文件... /認證演示/身份驗證演示/ libAuthentication.a,文件是爲了歸檔而構建的,而不是被鏈接的架構(i386)'。我現在正在努力,但目前還沒有運氣。 – woz 2012-07-12 18:34:41