[Cocoa] Problema al guardar datos a disco con NSCFString
Llevo varios dias con esto y no doy con la tecla. Lo gordo de la aplicación esta hecha en C++, después tengo hecho el interface en Objective C++.
Tengo un NSTableView que muestra una lista de etiquetas, cuando se modifican se llama al delegado - (void)tableView: (NSTableView *)tableView setObjectValue: (id)object forTableColumn: (NSTableColumn *)tableColumn row: (NSInteger)row Y allí modifico el valor en una clase en C++, después al guardar los datos a disco convierto la tabla en C++ a NSMutableArray con objetos de tipo Label.
No entiendo dos cosas.
1. dependiendo del nombre que le ponga a la etiqueta esta me viene en el campo object (del delegado) como NSTaggedPointerString* o como NSCFString*, WTF!?!?!
2 Cuando vuelco los datos de C++ al NSMutableArray (etiquetas modificadas) aunque todas pasen por la misma llamada, el campo name de las etiquetas se guardan como NSTaggedPointerString y otras como NSCFString, estas ultimas dan problemas al leerlas después.
Código:
- (void)saveConfig:(NSString *)filename{
NSMutableDictionary *root = [NSMutableDictionarydictionary];
[root setValue: [NSNumbernumberWithInteger: mLoadAddress] forKey:@"loadAddress"];
[root setValue: [NSNumbernumberWithInteger: mStartAddress] forKey:@"startAddress"];
[root setValue: [NSNumbernumberWithInteger: mSystem] forKey:@"system"];
[root setObject: [NSKeyedArchiverarchivedDataWithRootObject:entryPoints] forKey:@"entryPoints"];
// etiquetas modificadas
NSMutableArray *labelsModified = [[NSMutableArrayalloc] init];
for ( auto &label : mSymbolTableModified )
[labelsModified addObject:[[Label alloc] initLabel:[NSString stringWithUTF8String:label.second.name.c_str()] withValue:label.second.address]];
[root setObject: [NSKeyedArchiverarchivedDataWithRootObject:labelsModified] forKey:@"labels"];
// chunks
NSMutableArray *chunks = [[NSMutableArrayalloc] init];
for ( auto c : mChunks )
{
[chunks addObject:[[MemoryBlockalloc] initWithAddress:c.startendAddress:c.endrelocateTo:c.org
type:[NSString stringWithUTF8String:c.type.c_str()]
parameters:[NSString stringWithUTF8String:c.params.c_str()]]];
}
[root setObject: [NSKeyedArchiverarchivedDataWithRootObject:chunks] forKey:@"chunks"];
[[NSUserDefaultsstandardUserDefaults] setObject:root forKey:filename];
}
Una captura de lo que hay en labelsModified antes de guardar.
¿Alguna idea de como corregir esto?
Puedo probar usando los bindings en vez del protocolo NSTableViewDelegate pero me da pereza ponerme a cambiar cosas.
No es lo mismo tener diez años de experiencia, que tener un año de experiencia diez veces.
It is an undisputed truth that the Atari ST gets the best out of coders. No dedicated hardware, just the CPU and a frame buffer! Some call it Spartan, others name it Power Without The Price, and a select few say `challenge accepted'! --- by spkr from smfx
Marcadores