Pregunta

I have set up a class that conforms to NSCoding, and works as expected when I first create the object. It is essentially the same set up as this

The problem I am having is that the properties of the object when changed are not kept.

For example,

Foo is created and has a property called name.

Foo.name = @"bar"

I can encode / decode the object and it retains the name bar.

If I try and change

Foo.name = @"newName"

The encode method is not called again, so foo.name remains as @"bar" (I have a log state within the encode method)

Also,

I am using a core data object, that has a transformable property which points to the foo object.

Thanks

¿Fue útil?

Solución

To "save" the object, you have to call the encode method, e.g. to write it to disk or send it to an output stream.

However, since you are using Core Data to persist the object, you have to call

[managedObjectContext save:&error];

to persist the object after changing it.

That being said, I do not think it makes a lot of sense to have a transformable property that points to a custom class that keeps a string property. Instead, you should think of a more appropriate data structure so you only need transformable properties for non standard data types that cannot be persisted by using the standard data types already built into Core Data.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top