给定以下简单的模型类(基于Mantle):
// .h
#import <Mantle.h>
@interface JAIInterestingPhonesCategory : MTLModel <MTLJSONSerializing>
@property (copy, nonatomic, readonly) NSString *categoryId;
@property (copy, nonatomic, readonly) NSString *title;
@end
// .m
#import "JAIInterestingPhonesCategory.h"
@implementation JAIInterestingPhonesCategory
+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
return @{
@"categoryId" : @"id",
};
}
@end我创建了以下TestCase:
#import <XCTest/XCTest.h>
#import "JAIInterestingPhonesCategory.h"
@interface JAIInterestinPhoneTestCase : XCTestCase
@end
@implementation JAIInterestinPhoneTestCase
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testCreateModelWithJSONDictionary
{
NSDictionary *JSONModelDictionary = @{
@"id" : @"catId",
@"title" : @"Category title"
};
NSError *error;
JAIInterestingPhonesCategory *category = [MTLJSONAdapter modelOfClass:[JAIInterestingPhonesCategory class] fromJSONDictionary:JSONModelDictionary error:&error];
XCTAssertNotNil(category, @"The instantiated category must not be nil");
}
@end我得到了折叠运行时错误:
*** Assertion failure in -[MTLJSONAdapter initWithJSONDictionary:modelClass:error:] Invalid parameter not satisfying: [modelClass isSubclassOfClass:MTLModel.class]
正如你所看到的,modelClass(a.k.a. )JAIInterestingPhonesCategory)是MTLModel的一个子类。
我把Mantle作为一个Pod加入了这个项目。
知道这是怎么回事吗?谢谢!
发布于 2014-06-05 10:37:12
这里的问题是,Mantle被注入您的测试和您的主要目标。
这里的解决方案是相应地更改podfile:
platform :ios, '7.0'
target :app do
pod 'Mantle', '~> 1.4'
end
target :appTests do
pod 'Expecta', '~> 0.3'
end有关更多信息,请访问https://github.com/Mantle/Mantle/issues/217。祝好运!
https://stackoverflow.com/questions/24048112
复制相似问题