Is it possible to save a block inside an NSManagedObject?

I want to save the block inside the NSManagedObject master data, if possible. I have an inherited class from NSManagedObject. This class has a block to satisfy some asynchronous calls. I tried to save the block as an attribute of Transformable and Transient. when I try to call a block before loading my NSManagedObject, I have poor memory access "EXC_BAD_ACCESS".

If I do not check the transformable flag, I have an exception similar to this:

-[__NSStackBlock__ encodeWithCoder:]: unrecognized selector sent to instance 0xbfffd930

I am new to iOS. I work under the iOS 5 SDK with ARC support. This is an excerpt from my code:

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

@class ModbusRegister, Board;
typedef void (^DataBlockType)(NSArray *listRegister);

@interface EnergyEntry : NSManagedObject
- (void)invokeWithData: (NSArray *)listRegister;

@property (nonatomic, copy) DataBlockType  datablock;

@end

#import "EnergyEntry.h"

@implementation EnergyEntry

@dynamic datablock;

- (void)invokeWithData: (NSArray *)listRegister{

    self.datablock(listRegister);
}

@end

When I tried to save the block:

[energyEntry setValue:@"Energía activa" forKey:@"name"];
[energyEntry setValue:[NSNumber numberWithDouble:0] forKey:@"value"];
[energyEntry setValue:currentBoard forKey:@"board"];

[energyEntry setValue:^(NSArray *listRegister){
    //...my block operations to store
} forKey:@"datablock"];

Finally, when I call the block and the error starts:

NSArray *listRegister=... //my ready array
[energyEntry invokeWithData:listRegister];
+5
source share
1

. Apple NSData. NSData, , , .

, . , . . , , , , , .

+3

All Articles