Por alguna razón atributos están siendo devueltos como NSArrays en mi artículo objeto toda la NSString mecanografiadas. Aquí está mi función para recuperarlos: datos básicos de regresar NSArrays en lugar de NSStrings
- (NSArray *)getSavedArticles
{
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSError *error = nil;
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Article" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
NSSortDescriptor *dateSort = [NSSortDescriptor sortDescriptorWithKey:@"last_opened" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:dateSort]];
NSArray *fetchedObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];
return fetchedObjects;
}
no he creado un NSManagedObjectModel para estos, y en su lugar sólo estoy acceder a ellos usando MVA.
//self.data has the array returned from getSavedArticles
NSManagedObject *object = [self.data objectAtIndex:indexPath.row];
NSString *path = [object valueForKey:@"path"];
NSString* id = [object valueForKey:@"id"];
Cuando miro esta en el panel de las variables, en path
y id
veo (__NSArrayI *) ... Variable is not a CFString.
Impresión de la descripción de cualquiera de estos también imprime el paréntesis se utiliza cuando se imprime matrices.
Me pregunto si esto podría deberse al descriptor de clasificación? He comprobado dos veces que los datos que entran en estos objetos están escritos correctamente, y la base de datos SQLite que estoy usando para hacer una copia de seguridad de todo está mostrando cadenas.
He intentado reinstalar la aplicación en el simulador y restablecerla. Todavía obtengo un NSArray en lugar de un NSString.
Realmente no sé lo que está pasando aquí. Cualquier ayuda sería apreciada.
EDIT: Acabo de encontrar algo más interesante. Hago otro control para ver si se ha guardado un artículo, y esta vez no recibo un NSArray para la ruta del artículo:
- (NSString *)hasArticleSaved:(NSString *)id
{
NSString *path = nil;
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"%K == %@", @"id", id]];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Article" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];
if (fetchedObjects.count > 0) {
NSManagedObject *savedArticle = [fetchedObjects objectAtIndex:0];
path = [savedArticle valueForKey:@"path"];
}
return path;
}
Ahora estoy realmente confundido. ¿Ningún arrendatario?
¡Vaya! Eso es un error tipográfico en la pregunta. Estoy usando objectAtIndex. Arreglando ahora. – MishieMoo
Sí, me preguntaba cómo eso compilado. – TechZen