Note that there are some explanatory texts on larger screens.

plurals
  1. POPattern for determining if object is fully or partially loaded
    text
    copied!<p>The question does not strictly tied with iOS, but since I encountered this in iOS app I will speak in terms of Objective-C.</p> <p>My iOS app is a client, which gets some data from server. The data from server is json, and it is mapped with my classes. The problem appears when the server send only the necessary part of the object.</p> <p>Lets say the full object is</p> <pre><code>{ "a" : 1, "b" : 2, "c" : 3 } </code></pre> <p>My class to which it is mapped is</p> <pre><code>@class MyObject { int a, b, c; } @property (nonatomic) int a, b, c; -(id) initFromDictionary:(NSDictionary*)dict @end @implementation MyObject -(id) initFromDictionary:(NSDictionary*)dict { self = [super init]; if (self) { a = [dict[@"a"] intValue]; b = [dict[@"b"] intValue]; c = [dict[@"c"] intValue]; } return self; } @end </code></pre> <p>The server can send</p> <pre><code>{ "a" : 1, "c" : 3 } </code></pre> <p>for request <code>getAandC</code> and </p> <pre><code>{ "a" : 1, "b" : 2 } </code></pre> <p>for another - <code>getAandB</code> (these requests are not dependent, the only thing they are similar is the object they use). I do not need any information about <code>b</code> in the first one and about <code>c</code> in the second one.</p> <p>The problem is the following. When I write code for these requests I surely know which fields are returned and do not use empty field, but after some time I may forget about which request returned partial object or full, and try to use empty field. So there can be a lot of errors, which could be hard to find.</p> <p>Is there any practices for that case or maybe some pattern for determining if the object is fully or partially loaded and warning the developer about it?</p>
 

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