ios - Migration from homemade models to core data models: setter/getter issue -


I am starting to learn how to use core data for my app, and I have no idea about setter The question is and NSManagedObject .

In my old model I was using this syntax to declare attributes:

@interface MyModel: NSObject {MyAttributeOfClass * _myAttributeOfClass} - (zero) SetMyAttributeOfClass: (MyAttributeOfClass *) anAttributeOfClass; - (MyAttributeOfClass *) myAttributeOfClass;

I know, I can use the @ synthesis to do this stuff. But if I use @ synthesis with a public attribute:

  @property (nonatomic, strong) MyAttributeOfClass * myAttributeOfClass;  

A developer can bypass my setter and set a value for myAttributeOfClass : myAttributeOfClass = bar; I do not want to allow this behavior because I use a setter for any action. If this work is not done, then my class will no longer function properly.

So, now I am migrating my old model from core data model to subdivision from NSManagedObject .

But when I create a square from my data model, the attributes are declared as such:

  @property (nonatomic, retain) MyAttribute * myAttribute;  

So, a developer can set a value for this attribute without calling a setter: myAttribute = bar; And I would like to refuse it.

Any suggestions?

Thank you!

The properties of the core data managed object are not backed up depending on the variable of the instance A feature can be set using syntax:

  object.myAttribute = bar;  

or with key-value coding:

  [object set value: for bar: @ "myAttribute"];  

and setter method in both cases

  - (zero) setMy attribute: (MyAttribute *) value;  

The setter and gestetter method are usually created dynamically at runtime, but you can provide your own clear setter and / or gestetter method.

However, it is possible to bypass the setter by calling "primitive" accessory methods and:

[Object setprimitative value: Key for Bar: @ "MyAttribute"];

This will use a custom setter method, but anyone can call the primitive accessor, there is no hindrance in it.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -