Domanda

Data la seguente classe di modello semplice (basata sul mantello):

// .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
.

Creo la seguente prova:

#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
.

E ottengo l'errore di runtime FOLLWING:

*** Assertion failure in -[MTLJSONAdapter initWithJSONDictionary:modelClass:error:] Invalid parameter not satisfying: [modelClass isSubclassOfClass:MTLModel.class]

E, come puoi vedere, modelClass (a.k.a. JAIInterestingPhonesCategory) è una sottoclasse di MTLModel.

Ho aggiunto il manto al progetto come un pod.

Qualche idea di cosa sta succedendo qui?Grazie !!!

È stato utile?

Soluzione

Il problema qui è che il mantello viene iniettato in entrambi i test e il tuo obiettivo principale.

Una soluzione qui è cambiare il tuo Podfile di conseguenza:

platform :ios, '7.0'

target :app do
    pod 'Mantle', '~> 1.4'
end

target :appTests do
  pod 'Expecta',     '~> 0.3'
end
.

Check https://github.com/mantle/mantle/issues/217 per maggiori informazioni. Buona fortuna!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top