0
Ich verwende die Methode NSEntityMigrationPolicy
und createDestinationInstancesForSourceInstance
, um einen Attributtyp von Data
in String
zu ändern. Es erzeugt jedoch neue Objekte, anstatt die vorhandene zu ersetzen.NSEntityMigrationPolicy erstellt ein neues Objekt anstelle einer bestehenden Änderung
Hier ist mein Code:
#import "MessageTransformationPolicy.h"
@implementation MessageTransformationPolicy
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance
entityMapping:(NSEntityMapping *)mapping
manager:(NSMigrationManager *)manager
error:(NSError **)error
{
// Create a new object for the model context
NSManagedObject *newObject =
[NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName]
inManagedObjectContext:[manager destinationContext]];
// do our transfer of nsdate to nsstring
NSData *messageMetadata_dataType = [sInstance valueForKey:@"metadata"];
NSString *messageMetadata_stringType = [[NSString alloc] initWithData:messageMetadata_dataType encoding:NSUTF8StringEncoding];
// set the value for our new object
[newObject setValue:messageMetadata_stringType forKey:@"metadata"];
// do the coupling of old and new
[manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping];
return YES;
}
@end
Wo liegt das Problem?