2014-09-24 103 views
2

與XCTest一起使用CocoaLumberJack時,出現無法找到DDLog.h的錯誤。我試過把它改爲<CocoaLumberjack/DDLog.h>,但沒有運氣。該項目在iOS模擬器中工作的LumberJack編譯並運行良好,但是當我爲單元測試目標運行它時,出現此錯誤(請參閱屏幕截圖)。CocoaLumberJack XCTest鏈接器運行測試用例時出錯

這裏是我的-Prefix.pch

#import <Availability.h> 

    #ifndef __IPHONE_5_0 
    #warning "This project uses features only available in iOS SDK 5.0 and later." 
    #endif 

    #ifdef __OBJC__ 
     #import <UIKit/UIKit.h> 
     #import <Foundation/Foundation.h> 
     #import <CoreData/CoreData.h> 
     #import <CocoaLumberjack/DDLog.h> 
     #import "Utilities.h" 
    #endif 


    #ifdef DEBUG 
    static const int ddLogLevel = LOG_LEVEL_VERBOSE; 
    #else 
    static const int ddLogLevel = LOG_LEVEL_ERROR; 
    #endif 

錯誤:

Error

我鏈接的庫向tests目標也爲與libPods.a如下圖所示。

Linked Libraries

爲什麼不樵夫鏈接正常運行的TestCase的時候?還有什麼我需要添加到TestTarget爲它正確鏈接?

回答

1

我能夠通過刪除-Prefix.pch文件的自定義設置並重新格式化podfile以使用目標來解決該問題。我不得不把

#import "DDLog.h" 

#ifdef DEBUG 
static const int ddLogLevel = LOG_LEVEL_VERBOSE; 
#else 
static const int ddLogLevel = LOG_LEVEL_ERROR; 
#endif 

移動到`Utility.h」類。

podfile重建這兩個目標鏈接:

platform :ios, '7.0' 

def common_pods 
    pod 'CocoaLumberjack' 
    pod 'HexColors' 
end 

target :MyApp do 
    common_pods 
end 

target :MyAppTests do 
    common_pods 
end 

我也不得不從兩個目標中刪除libPods.a,因爲它不再建造。相反,libPods-MyApp.alibPods-MyAppTests.a是使用新的podfile配置構建的。

相關問題