Re: "context-aware" bindings
Re: "context-aware" bindings
- Subject: Re: "context-aware" bindings
- From: Mikkel Eide Eriksen <email@hidden>
- Date: Sun, 27 Feb 2011 17:46:12 +0100
On 27/02/2011, at 17.19, Joanna Carter wrote:
> Le 27 févr. 2011 à 15:25, Mikkel Eide Eriksen a écrit :
>> It would only return nil in some cases. I'm working on some Gedcom <-> Core Data code. All objects in Gedcom have a "tag" identifier. One such object is an "Event", with the generic tag EVEN. There are multiple subtypes of Event, such as BIRT (birth), DEAT (death), CONF (confirmation), etc.
>>
>> An Event can also have a "type", which in the case of generic EVENs is something for which no specific tag exists. So:
>>
>> Event with type "Birth" should become:
>> 1 BIRT
>> 2 DATE ...
>> 2 PLAC ...
>>
>> generic Event with some type should become:
>> 1 EVEN
>> 2 TYPE Event Type
>> 2 DATE ...
>> 2 PLAC ...
>>
>> My current implementation of the type getter on the Event object checks to see if the type is one of the known tags (Birth, etc), and returns nil so as to avoid redundant data:
>>
>> 1 BIRT
>> 2 TYPE Birth
>> 2 DATE ...
>> 2 PLAC ...
>>
>> I think I'll probably use a displayType property for bindings, and the internal type property for writing out to Gedcom. Another option would be to subclass Event into all the different types, but that seems overkill.
>
> If you are displaying the event's "tag", then all you need is to return the appropriate string; the event getter can check what to return.
>
> But, if you are transforming to/from an event from/to something else that should contain the tag value, then what about using a variation of the Visitor design pattern?
>
> Are you creating something from the event, or an event from something else? Can you let us see an idea of the two classes involved?
I do both. I create the event from gedcom data, and create gedcom data from the event.
http://code.google.com/p/cocoa-gedcom/wiki/Design
The "type" code in question is below:
http://code.google.com/p/cocoa-gedcom/source/browse/trunk/GCCoreData/src/GCEvent.m#247
When creating gedcom data, it is accessed via GCEvents superclass GCObject:
http://code.google.com/p/cocoa-gedcom/source/browse/trunk/GCCoreData/src/GCObject.m#380
Since the tagDict is built dynamically at runtime, I should mention it looks like this:
{
key = type;
tag = TYPE;
type = attribute;
}
Which means the actual part of gedcomNode that executes is lines 411+. Note that almost all attributes are simply written out as-is, it's only for the specific case of an Event which has a type that means the same thing as its tag that I don't want the value.
I just now added a displayType, and this works (I can show "Birth" in the GUI and nothing in the Gedcom data), but as I mentioned it doesn't seem so clean to have two ways of accessing the same primitiveType.
Regards,
Mikkel
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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