• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Validation error in a relationship? (in coredata)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validation error in a relationship? (in coredata)


  • Subject: Re: Validation error in a relationship? (in coredata)
  • From: Chris Hanson <email@hidden>
  • Date: Tue, 16 Oct 2007 16:58:47 -0700

Your code is still incorrect. Just looking at <http://pastebin.com/m38aa3280 >...

(1) Your -setMessageBody: method is not using the *change* notification methods, it is using the *access* notification methods. This is incorrect.

(2) Your -messageBody: method is not using the access notification methods, it is just returning the result of -primitiveValueForKey:. This is incorrect.

You have similar errors in the rest of your code, at least from looking at <http://pastebin.com/m65f42c4b>. I strongly recommend reading up a bit more on how to write Core Data accessors and ensuring the correctness of your code with respect to the Core Data documentation. I suspect that will help resolve the problem in your code a lot more quickly, and help prevent more problems of this kind from cropping up.

You also have a grave error in your -[ANTStArticle initWithSubject:andReplyTo:] method; you are allocating another instance of ANTStArticle and assigning it to "self" in the method. Either you should write what it looks like you're trying to write as a class method (e.g. +articleWithSubject:replyTo:) or you should invoke the designated initializer on super without instantiating another ANTStArticle.

Furthermore, you need to be aware that only your code will ever invoke your -initWithSubject:andReplyTo: method; Core Data will know nothing about it, and if Core Data itself is ever used to instantiate your DRAFT entity (say via an NSArrayController) it will simply invoke the designated initializer. Any initialization that must happen when an instance of ANTStArticle is first inserted in a managed object context should go in an override of -awakeFromInsert.

My specific recommendations for your code:

(1) Rewrite the accessor methods for your modeled Core Data properties to invoke the -{will,did}{Access,Change}ValueForKey: methods correctly. The -{will,did}AccessValueForKey: methods should be invoked in getters around -primitiveValueForKey:, while the - {will,did}ChangeValueForKey: methods should be invoked in setters around -setPrimitiveValue:forKey:.

(2) Override -awakeFromInsert on ANTStArticle to perform any initialization that must always happen for instances of the DRAFT entity after they are inserted in a managed object context. See the Core Data documentation for how to correctly override - awakeFromInsert; you need to invoke [super awakeFromInsert], and there are other issues you will probably need to consider as well.

(3) Change -[ANTStArticle initWithSubject:andReplyTo:] to a class method +[ANTStArticle articleWithSubject:inReplyTo:] that returns a new autoreleased instance of your DRAFT entity, with whatever additional setup is correct for that entity. In general, use + [NSEntityDescription insertNewObjectForEntityForName:inMangedObjectContext:] to create new instances of an entity, rather than +alloc/- initWithEntity:insertIntoManagedObjectContext:. You will be more likely to write correct code that way.

 -- Chris

On Oct 16, 2007, at 3:35 PM, malcom wrote:

ops.
Fixed a problem with custom accessor mehtod in ANTStArticle_Content.
Should be ok now (http://pastebin.com/m38aa3280).
But the problem persist.
Umpf where f* is the error? :((

On 10/16/07, malcom <email@hidden> wrote:
Hell's Kitchen/Dexter/Malcolm:

Hello Chris, I'm sorry but I've encountered some problems with my gmail account and apple ml so I've created another accounts.

Well, regarding the problem I've created right (?) custom accessor
methods but the problem persist. This is the code:
ANTStArticle.m -> http://pastebin.com/m65f42c4b
ANTStArticle_Content.m -> http://pastebin.com/m57644dd9
While you can download the entire project here:
http://www.mediafire.com/?5iyukzukm20

The problem still to be this:
NSError "draftContent is not valid." Domain=NSCocoaErrorDomain
Code=1550 UserInfo={
NSLocalizedDescription = "draftContent is not valid.";
NSValidationErrorKey = draftContent;
NSValidationErrorObject = <ANTStArticle: 0x3244d0> (entity: DRAFT;
id: 0x336850 <x-coredata:///DRAFT/tCA7B7E93-3242-40D2-B324-6D3FF369E009 >
; data: {
draftConnection = -1;
draftContent = 0x33b0e0
<x-coredata:///DRAFT_CONTENT/tA2EE9788-F757-4A55-BF5D-7DC7122FBB9D>;
draftIsSentArticle = 0;
draftIsSuspended = 0;
draftLocked = 0;
draftMarkAndSendNextTime = 0;
draftMessageID = uid;
draftNewsgroups = nil;
draftProfile = -1;
draftReplyToID = nil;
draftSendLaterTime = nil;
draftSentDate = nil;
draftSignName = -1;
});
NSValidationErrorValue = <ANTStArticle_Content: 0x3314c0> (entity:
DRAFT_CONTENT; id: 0x33b0e0
<x-coredata:///DRAFT_CONTENT/tA2EE9788-F757-4A55-BF5D-7DC7122FBB9D> ;
data: {
messageBody = "";
messageHeaders = <040b7374 7265616d 74797065 6481e803 84014084


8484134e 534d7574 61626c65 44696374 696f6e61 72790084 840c4e53 4469>;
});
}



--
www.malcom-mac.com - independent software developer
mail: email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Validation error in a relationship? (in coredata)
      • From: malcom <email@hidden>
    • Re: Validation error in a relationship? (in coredata)
      • From: Jim Correia <email@hidden>
References: 
 >Re: Validation error in a relationship? (in coredata) (From: Ron Lue-Sang <email@hidden>)
 >Re: Validation error in a relationship? (in coredata) (From: "dexter.cocoa dexter" <email@hidden>)
 >Re: Validation error in a relationship? (in coredata) (From: Chris Hanson <email@hidden>)
 >Re: Validation error in a relationship? (in coredata) (From: malcom <email@hidden>)
 >Re: Validation error in a relationship? (in coredata) (From: malcom <email@hidden>)

  • Prev by Date: Re: Class vs +class: Cocoa/Obj-C design question
  • Next by Date: Print out does not work on Panther
  • Previous by thread: Re: Validation error in a relationship? (in coredata)
  • Next by thread: Re: Validation error in a relationship? (in coredata)
  • Index(es):
    • Date
    • Thread