简体   繁体   English

在GET上创建的RestKit受管对象始终为布尔返回false

[英]RestKit managed object created on GET returns false for bool always

I am doing a GET call with rest kit with an entity mapping which has a boolean isPrimary. 我正在使用带有布尔值isPrimary的实体映射的rest kit进行GET调用。 The call is successful and the mapping array also has the correct value for isPrimary when i nslog it. 调用成功,并且在我nslog记录时,映射数组还具有isPrimary的正确值。 But when i retrieve the entity form core data using a simple fetch request with out any predicate the value is always "false". 但是,当我使用不带任何谓词的简单获取请求来检索实体形式的核心数据时,该值始终为“ false”。 All non boolean vars are correct. 所有非布尔型var都是正确的。 Any help is much appreciated.cheers 任何帮助都非常感谢。

The Header: 标头:

#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

output JSON on success: 成功输出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

When using a managed object context in a multi-threaded environment you need to be careful to use the context only on the intended thread. 在多线程环境中使用托管对象上下文时,需要注意仅在预期线程上使用上下文。 The main thread has a specific context and each background thread must have a new context created for it. 主线程具有特定的上下文,每个后台线程必须具有为其创建的新上下文。 If you use the wrong context for a thread (or access a private queue context without using the private queue) then you will see strange issues and / or exceptions. 如果为线程使用了错误的上下文(或在不使用私有队列的情况下访问了私有队列上下文),则会看到奇怪的问题和/或异常。 The type of issues you will see depend on what is already saved into the context and what operations you try to perform, but it will generally never be correct. 您将看到的问题类型取决于已保存到上下文中的内容以及尝试执行的操作,但是通常永远不会正确。

So, take care to use only the appropriate context and that the relationships between contexts ensure that newly saved data is notified and updated where you need it. 因此,请注意仅使用适当的上下文,并且上下文之间的关系可确保在需要时通知和更新新保存的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM