【发布时间】:2011-12-31 21:16:01
【问题描述】:
首先:为什么 obj-c 项目的依赖管理如此痛苦?!
我正在 Objective-c 中为我的 RESTful 服务编写一个包装器。服务器是一个简单的 sinatra 应用程序,在本地运行在 'http://localhost:4567' 上。
我按照here 列出的步骤包含了 RestKit。
我知道 RestKit 已正确“安装”到我的项目中,因为当我执行 #import <RestKit/RestKit.h> 时,项目构建得很好。
现在,我正在使用 SenTesting.Framework 测试我的库。我的主库中有一个类,如下所示:
#import "CITWCore.h"
#import <RestKit/RestKit.h>
@implementation CITWCore
- (id)init
{
self = [super init];
if (self) {
RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:4567"];
// Initialization code here.
}
return self;
}
@end
还有我的单元测试类:
#import "CITWCoreTests.h"
@implementation CITWCoreTests
- (void)testItCreatesAnInstance
{
CITWCore *newCoreObject = [[CITWCore alloc]init];
STAssertNotNil(newCoreObject, @"new object should not be nil");
}
@end
当我使用 ⌘U 运行测试时,测试失败并显示以下消息:
error: testExample (CITWCoreTests) failed: -[__NSCFString isIPAddress]: unrecognized selector sent to instance 0xa115880
RKClient.m 中的第 292 行触发了错误
if ([newBaseURLString isEqualToString:@"localhost"] || [hostName isIPAddress]) {
RestKit 项目中有一个名为“NSString+RestKit.h”的头文件,其中包含 -isIPAddress 方法声明,据我所知,它被包含在内,所以我不知道为什么编译器/运行-time 不知道那个特定的方法。我配置测试目标的方式有问题吗?如何创建 RKObjectManager 的实例并让这个测试通过?
更抽象地说:人们如何管理这样的依赖关系?我正在查看VenderKit 之类的东西,但它似乎缺乏文档,而且我认为我对编译器和链接器如何工作以达到那么大的抽象没有正确的理解。将静态库链接到我的项目(它本身就是一个静态库)时,有哪些一般准则?
【问题讨论】:
-
有人吗?这个问题没有意义吗?
-
您确定
#import <RestKit/RestKit.h>在 CITWCoreTests.m 中吗?如果没有,那么您将收到该错误
标签: objective-c ios xcode restkit