我有一个具有多个属性的实体, 其中之一是最后修改日期。 当任何对象属性被设置时, 我想更新最后修改日期 。
如果我没有使用核心数据, 我会为这些属性提供我自己的设置, 并更新上一个修改日期。 然而, 我不确定我是否应该和 CoreData 的属性乱搞 。
这样做的最佳方法是什么?
我有一个具有多个属性的实体, 其中之一是最后修改日期。 当任何对象属性被设置时, 我想更新最后修改日期 。
如果我没有使用核心数据, 我会为这些属性提供我自己的设置, 并更新上一个修改日期。 然而, 我不确定我是否应该和 CoreData 的属性乱搞 。
这样做的最佳方法是什么?
高压安装器很容易完成, 您必须确保您发出正确通知, 以便其他一切工作( 包括KVO) 。
- (void) setThing:(NSObject *)myThing {
self.lastUpdateDate = [NSDate date];
[self willChangeValueForKey:@"thing"];
[self setPrimitiveThing:myThing];
[self didChangeValueForKey:@"thing"];
}
说到这里,如果你需要做的只是我显示的代码(主要是设定值和更新上一个更新日期),你最好使用Key-Value Survey,并对通知作出反应。它更容易,更干净。
如果您重新与NSManagedObject子类合作, 因为这些操作是在运行时提供的( 即 < code> 动力 code >, 而不是 < code\\ synthesize code > ) 。 如果您真的想要的话, 您可以推翻属性变异器( 发音器), 但是它会更乱, 没有理由。 相反, 使用密钥值观测( KVO) 。 它会让您知道值何时被更改 。
苹果 s KVO 文件非常丰富: < a href="https:// developmenter.apple.com/library/mac/document/Cocoa/Conceptitual/KeyValueObsession/KeyValueObsesser/KeyValueObsesser.html#/apple_ref/doc/uid/100001775i" rel="nofolpol" >https://developer.apple.com/library/mac/document/Cocoa/Conceptitual/KeyValueObsesser/KeyValueObservice.html#/apple_ref/doc/uid/10000177i
I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...
I have a UITextField that is a subview of a UITableViewCell. When my view loads, I want the text field to become first responder. I have a pointer to the text field in the table cell, so to do this I ...
I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...
I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...
Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...
I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...
Is there a way to add a location from an MKMapView in my application to the built-in Google Maps app? From what I understand there is probably one of two ways to do it: using [[UIApplication ...
I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...