English 中文(简体)
核心数据检索 次级类别内的反对归属
原标题:Core Data retrieve NSManagedObject attribute from within subclass

I have a core data entity and I ve created a NSManagedObject subclass. Say it has a attribute, "attrib1" within entity "List". In my subclass, in some cases I d like to calculate the value of attrib1, in other cases I d like to return the value from the database. I m trying to figure out how to return the database value from within my method. Example:

- (NSString *)attrib1 {
   if (flag) {
       return [self calculateValue];
   } else {
       // return value from core data, ie pass thru, but how?
       // Attempt1:
       return [super attrib1]; // Fails with  unrecognized selector 
       // Attempt2. Ends up calling this method again, recursion loop
       return [super performSelector:@selector(attrib1)];
   }
}

我应如何从作为切除1的跳板的NSManagedObject子级方法中收回“attrib1”这一特性的价值。

成就

最佳回答

首先,最好使其他财产能够从数据库中收回计算价值或取回,在这种情况下,应当留下来。 你们还缺少一些接线器。 因此,举例来说,法典应当照此办理:

-(NSString *)attrib1 {
    NSString *v;
    [self willAccessValueForKey:@"attrib1"];
    if(flag)
        v=[self calculateValue];
    else
        v=[self primitiveAttrib1];
    [self didAccessValueForKey:@"attrib1"];
    return v;
}

另见Ampado doc:

问题回答

暂无回答




相关问题
selecting textareas

I am trying to select specific element types in a row and change their attribute, specifically the id and name attributes. Using the following works fine for single line text input boxes: $( input:...

Performance overhead of using attributes in .NET

1.. Is there any performance overhead caused by the usage of attributes? Think for a class like: public class MyClass { int Count {get;set;} } where it has 10 attibutes (...

How to remove "onclick" with JQuery?

PHP code: <a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a> I want to remove the onclick="check($id,1) so the link cannot be clicked or "check($id,...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签