Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIColor类别链接器错误_Ios_Unit Testing_Linker Errors_Uicolor - Fatal编程技术网

Ios UIColor类别链接器错误

Ios UIColor类别链接器错误,ios,unit-testing,linker-errors,uicolor,Ios,Unit Testing,Linker Errors,Uicolor,今天早些时候,我尝试将单元测试添加到我正在创建的静态框架的xcode项目中。在将单元测试目标添加到项目中之后,我能够成功运行单元测试模板,并让测试捕获默认断言。然后,在将要测试的文件导入新的SenTestCase子类后,我尝试运行测试,但由于链接器错误,我的UIColor类别无法通过测试生成。链接器错误的文本如下所示: Undefined symbols for architecture i386: "_CGColorGetComponents", referenced from:

今天早些时候,我尝试将单元测试添加到我正在创建的静态框架的xcode项目中。在将单元测试目标添加到项目中之后,我能够成功运行单元测试模板,并让测试捕获默认断言。然后,在将要测试的文件导入新的SenTestCase子类后,我尝试运行测试,但由于链接器错误,我的UIColor类别无法通过测试生成。链接器错误的文本如下所示:

Undefined symbols for architecture i386:
  "_CGColorGetComponents", referenced from:
      -[UIColor(ColorExtension) hexValue] in StaticFramework(StaticFramework)
  "_CGColorGetNumberOfComponents", referenced from:
      -[UIColor(ColorExtension) hexValue] in StaticFramework(StaticFramework)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
接下来,我找到了这两个引用在我的项目中的位置。两者都属于以下功能下的“我的类别”:

- (NSString *)hexValue
{
    UIColor *color = self;
    const size_t totalComponents = CGColorGetNumberOfComponents(color.CGColor);
    const CGFloat * components = CGColorGetComponents(color.CGColor);
    return [NSString stringWithFormat:@"#%02X%02X%02X",
            (int)(255 * components[MIN(0,totalComponents-2)]),
            (int)(255 * components[MIN(1,totalComponents-2)]),
            (int)(255 * components[MIN(2,totalComponents-2)])];
}
如果我没记错的话,这两个都是NSColor类的一部分。稍加检查,我也注意到,在我的单元测试的框架文件夹中,UIKIT.Framework和Buffig.Framework都是红色的。我已尝试重新导入它们并构建,但这也无法解决该问题

有趣的是,只要相关的测试没有运行,我的静态框架仍然可以正常构建和运行。当我注释掉这个函数时(每次我使用它),单元测试构建时没有问题。在我假设丢失的UIKIT.Frase&基础框架可能导致链接器找不到NSCOLL属性时,我会是正确的吗?是否有任何其他建议可以解释为什么这些属性会导致这些问题,或者我可以做些什么来修复它们


任何帮助都将不胜感激。谢谢你的帮助

链接器错误表示您正在使用CoreGraphics函数,但未链接CoreGraphics框架


更新您的项目/目标,以便您链接CoreGraphics.framework,链接器问题将得到解决。

您是否将
CoreGraphics.framework
链接到您的项目?不,我在静态框架或单元测试中都不使用CoreGraphics.framework。是的。两个
CGColor…
函数来自CoreGraphics。您需要将
CoreGraphics.framework
链接到您的项目。这将修复链接器错误。我不确定这之前为什么会起作用,但将CoreGraphics.framework添加到我的StaticFramework目标和单元测试目标中修复了这个问题。你能把解决方案作为答案提交给我吗?