Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to update a model object through a model-controller (API wrapper) only
    primarykey
    data
    text
    <p>I have an iOS application with several model classes and a wrapper-class for API calls to a web-service that I am using as a model controller. </p> <p>Here is an example of a simple Model object.</p> <pre><code>@interface Person : NSObject @property (nonatomic, strong) NSString *firstName; @property (nonatomic, strong) NSString *lastName; + (Person *)personWithFirstName:(NSString *)firstName lastName:(NSString *)lastName; @end </code></pre> <p>To retrieve this object from the web service I have a model-controller in which I have implemented the following methods.</p> <pre><code>- (NSArray *)allPeople; - (void)addPerson:(Person *)newPerson; - (void)deletePerson:(Person *)newPerson; </code></pre> <p>This is great at the moment. However, I am now adding editing capability which I would also like to wrap in the model controller but am unsure as to the best way to structure this. Obviously, the easiest way to update a Person object would be to just access the properties on an object directly. But at the moment the model object does not know anything about the web service and I want to keep it that way. I could add a method to the model controller such as</p> <pre><code>- (void)updatePerson:(Person *)person withFirstName:(NSString *)newFirstName </code></pre> <p>or something similar and make the properties on the Person object readonly but this does not seem very intuitive. Still, I cannot think of any other way to do this without adding controller code into the model class. Does this seem like the appropriate way to handle this situation? Are there any other alternatives?</p> <p><strong>Update</strong> I do not know what I was thinking above, but I would be unable to make the properties on the model objects readonly since the Model Controller class would need to access and update those properties somehow. This means that it would be possible to update the person object directly bypassing the api wrapper which would be troublesome. Any help?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload