0

When I try to get a string value from an NSManagedObject, I get this

<Entity: 0x1e043140> (entity: Entity; id: 0x1e041c30 <x-coredata://8F48C331-B879-47B4-B257-4802A13ED12C/Entity/p4> ; data: {
number = "<UITextField: 0x1d8b7cc0; frame = (159 183; 161 30); text = 'test'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d8b3c10>; layer = <CALayer: 0x1d892a30>> : ";
})

how do I get the string from this (it's text = 'test';)

i get the object using this

NSString *rowValue = [self.fetchedResultsController objectAtIndexPath:indexPath];

ok, well the nsmanaged object is this and sets a uitableview cell to its string

NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];

cell.textLabel.text = [[object valueForKey:@"number"] description];

The reason it's showing what it does is because, as you can see, I am getting it's description. I can't find a property that would return the text value, so does anyone know how? Thanks.

Chris Loonam
  • 5,735
  • 6
  • 41
  • 63

3 Answers3

1

I assume that the error already occurs when you store a value in the managed object. Perhaps you do something like

[myObject setValue:[aTextField description] forKey:@"number"]

instead of storing the text field's text contents:

[myObject setValue:[aTextField text] forKey:@"number"]

UPDATE: As you write in a comment, the managed object values are stored as

NSString *string = [NSString stringWithFormat:@"%@ : %@", self.numtext, self.comtext];
[newManagedObject setValue:string forKey:@"number"];

But the %@ format for a UITextField itself is expanded to the text fields description, not the text contents. Therefore the string already looks like

"<UITextField: 0x1d8b7cc0; frame = (159 183; 161 30); text = 'test'; .... "

and this string is stored as "number" attribute in the managed object. You should use the following code instead:

NSString *string = [NSString stringWithFormat:@"%@ : %@", self.numtext.text, self.comtext.text];
[newManagedObject setValue:string forKey:@"number"];

Note that you have to delete the old database when testing this to get rid of the already existing wrong entries.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
0
NSString *str = managedObject.objectID.URIRepresentation.absoluteString
János
  • 32,867
  • 38
  • 193
  • 353
-1

You should write:

Entity *entity = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *rowValue = entity.text;

Edit:

ok, then try object.number.text;

Levi
  • 7,313
  • 2
  • 32
  • 44