• 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: ADC Core Data article
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ADC Core Data article


  • Subject: Re: ADC Core Data article
  • From: Charlton Wilbur <email@hidden>
  • Date: Sat, 9 Apr 2005 10:01:14 -0400


On Apr 9, 2005, at 8:03 AM, Marcel Weiher wrote:


On 9 Apr 2005, at 10:37, Byron Ellis wrote:

On Apr 9, 2005, at 12:44 AM, Marcel Weiher wrote:

Wow! I must have missed that one. How do I express [matrix matrixTranslatedBy:2.3 y:[slider floatValue]] in KVC? Or how about: [[array1 select] isEqual:[array2 each]]?

[matTranslator setValue:matrix forKey:@"matrix"];
[matTranslator setValue:[NSNumber numberWithFloat:2.3] forKey:@"x"];
[matTranslator setValue;[NSNumber numberWithFloat:[slider floatValue] forKey:@"y"];


//alternately
//[matTranslator bind:@"y" to:slider withKeyPath:@"value" options:nil];


[matTranslator valueForKey:@"translated"];

I don't see how this shows that KVC is isomorphic to message sending, as it assumes the existence of an additional element that is not part of KVC, at least I didn't notice a MatTranslator class as part of KVC. I could have missed it, though... ;-)

It's the right idea. Every message can be decomposed into setting one key for each argument, and either setting a Boolean key to indicate the arguments are complete or reading one key for each return value.


[matrix setValue: [NSNumber numberWithFloat: 2.3] forKey: @"translationInput"];
[matrix setValue: [slider floatValue] forKey: @"translationYInput"];
[matrix valueForKey: @"translationResult"]; // if it returns a value
[matrix setValue: [NSNumber numberWithBool: YES] forKey: @"translationInputSpecified"]; // if it does not


[[array1 select] isEqual:[array2 each]]?

This one is easier.

foo = [array1 getValueForKey: @"select"];
bar = [array2 getValueForKey: @"each"];
[foo setValue: bar forKey: @"isEqualInput"];
[foo valueForKey: @"isEqualResult"];

You can do it without one of the temporary variables, but it gets substantially more complex.

(Note that my only claim was that messages are isomorphic to key-value coding in expressive power, not that using them that way was likely to do good things for your code readability. In both of these instances I think the message-sending version is preferable by far.)

Charlton


-- Charlton Wilbur email@hidden email@hidden email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: ADC Core Data article
      • From: Marcel Weiher <email@hidden>
References: 
 >Re: ADC Core Data article (From: Philippe Mougin <email@hidden>)
 >Re: ADC Core Data article (From: Shawn Erickson <email@hidden>)
 >Re: ADC Core Data article (From: Charlton Wilbur <email@hidden>)
 >Re: ADC Core Data article (From: Marcel Weiher <email@hidden>)
 >Re: ADC Core Data article (From: Byron Ellis <email@hidden>)
 >Re: ADC Core Data article (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Re: Why would IBOutlet NSPanel *aWindow be nil?
  • Next by Date: Re: Packages vs. Finder (perceived stability problem)
  • Previous by thread: Re: ADC Core Data article
  • Next by thread: Re: ADC Core Data article
  • Index(es):
    • Date
    • Thread