title: NSManagedObject timeStamp update
body: <p>I want to track changes of NSManagedObject properties, in order to keep NSData *lastUpdate property "up to date"</p>
  
  <p>There are several approaches to get Notified when NSManagedObject changes its properties </p>
  
  <p>I. First is to override the setter Methods of all properties you want to track. Which is quite complicated in NSManaged object - check it <a href="https://stackoverflow.com/questions/6007633/is-it-possible-to-override-getters-and-setters-for-dynamic-properties-in-an-nsm/6008138#6008138">here</a></p>
  
  <p>II. Second could be a good one. You can just override "didChangeValueForKey" method That is called on every property change.</p>
  
  <pre><code>-(void)didChangeValueForKey:(NSString *)key{
      [super didChangeValueForKey:key];
      NSLog(@"Value for key:%@ has changed", key);
  }
  </code></pre>
  
  <p>Unfortunately we should not override this method due to the documentation that says...:</p>
  
  <blockquote>
    <p>"You must not override this method."</p>
  </blockquote>
  
  <p>III. Key-value-observing leads us back to IInd approach, with overriding "didChangeValueForKey".</p>
  
  <p>upd.
  IV. I tried to override -willSave method</p>
  
  <pre><code>-(void)willSave{
     NSArray *observedKeys = @[@"name", @"imageType"];
     NSDictionary * changesALL = self.changedValues;
     for (id key in changesALL){
         if ([observedKeys containsObject:key]){
             self.lastUpdate = [NSDate date];
             NSLog(@"updated For key: %@", key);
          }
      }
  }
  </code></pre>
  
  <p>This led infinitive loop, which is described in documentation.
  (altho the right approach is described here, so I've answered this question already)</p>
  
  <blockquote>
    <p>If you want to update a persistent property value, you should typically test for equality >of any new value with the existing value before making a change. If you change property >values using standard accessor methods, Core Data will observe the resultant change >notification and so invoke willSave again before saving the object’s managed object >context. If you continue to modify a value in willSave, willSave will continue to be called >until your program crashes.</p>
    
    <p>For example, if you set a last-modified timestamp, you should check whether either you >previously set it in the same save operation, or that the existing timestamp is not less >than a small delta from the current time. Typically it’s better to calculate the timestamp >once for all the objects being saved (for example, in response to an >NSManagedObjectContextWillSaveNotification).</p>
  </blockquote>