حدث خطأ أثناء اختبار نموذج Mantle على نظام التشغيل iOS

StackOverflow https://stackoverflow.com//questions/24048112

سؤال

بالنظر إلى فئة النموذج البسيطة التالية (استنادًا إلى 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(الملقب ب. JAIInterestingPhonesCategory) هي فئة فرعية من MTLModel.

لقد قمت بإضافة Mantle إلى المشروع باعتباره Pod.

هل لديك أي فكرة عما يحدث هنا؟شكرًا لك!!!

هل كانت مفيدة؟

المحلول

المشكلة هنا هي أنه يتم حقن 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 لمزيد من المعلومات.حظ سعيد!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top