在GET上创建的RestKit托管对象总是为bool返回false

时间:2014-05-28 04:31:30

标签: ios core-data restkit restkit-0.20

我正在使用具有实体映射的rest kit进行GET调用,该实体映射具有布尔值isPrimary。调用成功,并且当我使用nslog时,映射数组也具有正确的isPrimary值。但是当我使用简单的获取请求检索实体形式核心数据而没有任何谓词时,该值总是“假”。所有非布尔变量都是正确的。任何帮助都非常感谢.cheers

标题:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "StringBase.h"

@class MaterialPlantRel, PriceList, SalesOrder;

@interface Currency : StringBase

@property (nonatomic, retain) NSNumber * baseCurrency;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) SalesOrder *billingCurrencyInv;
@property (nonatomic, retain) PriceList *currencyTOInv;
@property (nonatomic, retain) MaterialPlantRel *ledgerCostCurrencyInv;
@property (nonatomic, retain) SalesOrder *paymentCurrencyInv;
@property (nonatomic, retain) MaterialPlantRel *replacementCostCurrencyInv;

// Returns a dictionary representation of the
// object with var keys and values;
-(NSDictionary*) getDictionaryRepresentation;

/** Override to map the values to object **/
-(void) setValuesForKeysWithDictionary:(NSDictionary *)keyedValues;

@end

成功时输出JSON:

        Sucess Currency (
        "<Currency: 0xda70f30> (entity: Currency; id: 0xb07e980 <x- coredata://C145A537-         5E8B-4E4E-95C1-BDFF10C84B05/Currency/p151> ; data: {\n    active = 1;\n    baseCurrency =    1;\n    billingCurrencyInv = nil;\n    code = BRL;\n    createdBy = nil;\n    currencyTOInv = nil;\n    ledgerCostCurrencyInv = nil;\n    modifiedBy = nil;\n    name = \"Brazilian Riaz\";\n    paymentCurrencyInv = nil;\n    replacementCostCurrencyInv = nil;\n    version = 1;\n})",
       "<Currency: 0xda6c0b0> (entity: Currency; id: 0xb07d000 <x-coredata://C145A537-5E8B-4E4E-95C1-BDFF10C84B05/Currency/p152> ; data: {\n    active = 1;\n    baseCurrency = 0;\n    billingCurrencyInv = nil;\n    code = USD;\n    createdBy = nil;\n    currencyTOInv = nil;\n    ledgerCostCurrencyInv = nil;\n    modifiedBy = nil;\n    name = \"US Dollars\";\n      paymentCurrencyInv = nil;\n    replacementCostCurrencyInv = nil;\n    version = 1;\n})"
        )

CoreData fetch : 

        NSFetchRequest* fetchRequest = [NSFetchRequest        fetchRequestWithEntityName:@"Currency"];
       // get the managed object context
       NSManagedObjectContext* l_MOC = [[[RestKitConfig ConfigManager] AppDelegateSales] managedObjectContext];
       // setup entity description
       NSEntityDescription* entityDescription = [NSEntityDescription
                                              entityForName:@"Currency"
                                              inManagedObjectContext:l_MOC];
       // fetch the request
      [fetchRequest setEntity:entityDescription];

    // Set example predicate and sort orderings...
    NSError* error;
    NSArray* array = [l_MOC executeFetchRequest:fetchRequest error:&error];

    if ([array count] > 0)
    {
        // copy of the retrieved data
        self.data = [array copy];
#ifdef _DEBUG
        NSLog(@"Currency Data retrieved : %i Objects",[array count]);
        for (int i = 0; i < [array count]; i++)
        {
            Currency* l_currency = [array objectAtIndex:i];
            NSLog(@"base currency -> %@",l_currency.baseCurrency);
        }
#endif

Output : 
2014-05-28 13:07:03.187 Sales[2110:1003] base currency -> 0
2014-05-28 13:07:03.187 Sales[2110:1003] base currency -> 0

1 个答案:

答案 0 :(得分:0)

在多线程环境中使用托管对象上下文时,需要注意仅在预期的线程上使用上下文。主线程具有特定的上下文,每个后台线程必须为其创建新的上下文。如果对线程使用错误的上下文(或在不使用专用队列的情况下访问专用队列上下文),那么您将看到奇怪的问题和/或异常。您将看到的问题类型取决于已保存到上下文中的内容以及您尝试执行的操作,但通常不会是正确的。

因此,请注意仅使用适当的上下文,并确保上下文之间的关系确保在您需要的地方通知和更新新保存的数据。