Re: Core data accessors for structs
Re: Core data accessors for structs
- Subject: Re: Core data accessors for structs
- From: Charles Steinman <email@hidden>
- Date: Mon, 25 Jun 2007 11:52:35 -0700 (PDT)
You aren't quite doing what the document suggests. In
the Core Data documentation, it recommends you have a
persistent "shadow" attribute that your normal
accessors will use. In this case, you might have a
binary blob called fooData that your foo getter
decodes on first access and your foo setter encodes.
Following the pattern there will keep KVC-compliance.
Cheers,
Chuck
--- MH <email@hidden> wrote:
> Hi Folks,
>
> I've been looking at:
>
>
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html
>
> Although this seems to work fine. Are there any
> other issues that I'm
> overlooking?
> Also, I'm concerned that I loose KVC compliance
> using these kinds of
> accessors.
> Is there a way to restore KVC in this situtation?
>
>
> - (myStruct)foo
> {
> [self willAccessValueForKey:@"foo"];
> myStruct bar = foo;
> [self didAccessValueForKey:@"foo"];
>
> NSData *fooAsData = [self valueForKey:@"foo"];
>
> if (structAsData != nil) {
>
> [structAsData getBytes:&bar
> length:sizeof(myStruct)];
> }
>
> return bar;
> }
>
> - (void)setFoo:(myStruct)newFoo
> {
> [self willChangeValueForKey:@"foo"];
> foo = newFoo;
> [self didChangeValueForKey:@"foo"];
>
> NSData *fooAsData = [NSData
> dataWithBytes:&newFoo
> length:sizeof(myStruct)];
>
> [self setValue:fooAsData forKey:@"foo"];
> }
>
> Many thanks.
____________________________________________________________________________________
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php
_______________________________________________
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