• 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: Set String methods for Flattened Relationship Attributes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set String methods for Flattened Relationship Attributes


  • Subject: Re: Set String methods for Flattened Relationship Attributes
  • From: David LeBer <email@hidden>
  • Date: Wed, 19 Oct 2005 22:16:22 -0400

On 19-Oct-05, at 5:39 PM, Janice Cheung wrote:

    Hi David!  :)

Thank you for your advice. I'll start again.

OK,

My head hurts.

I wrote out a great long-winded email about flattened attributes and relationships an setter and getter method names. But I think I need to stop now.

This is what I think you are trying to do. You are trying to take arrays of objects and reduce their values to comma separated strings for some reason. Why? I don't know.

Chuck identified the problem with your setter method when he said this:

Are you sure you read this? You pass in a parameter named value, don't use it, then assign the value that you want to replace to it.

Any anyway, this makes no sense. emailContactNames is a calculated value. You can't set it. Even if value is a string of email addresses, which belongs on which ServerContact?

I'm baffled too. Not only do I not know what you are doing wrong, I don't even know what you think you are doing. Time to start again.

So. Here is some thoughts:

You are writing too much code. Learn NSDictionary, NSArray, and NSSet you'll be glad you did.

I don't know, but get the idea you may be mutating values in your EO attribute accessors, don't do that. Write cover methods instead. If it is for presentation purposes don't put that in your EOs at all. It doesn't belong there.

If you are receiving an array of objects and you need to display their values separated by commas then use a WORepetition and have it build the presentation for you. That's what it's there for (and you write no code).

If you *really* need to have a comma separated string of your values for some other reason and you need that to happen in multiple places, write generic methods to do that.

Chuck's reply supplied an elegant way to do that. From it I got:

public String stringFromArray(NSArray array){
    NSSet aSet = new NSSet(array);
    return aSet.allObjects().componentsJoinedWithString(",");
}


If you need to accept comma separated strings of your values to go back to your database again (yuck, think really hard about why you need this) you will need to write a method to turn the string back into an array before moving forward.


Take a look at: NSArray.componentsSeparatedByString(String components, String separator)

public NSArray arrayFromString(String value) {
    return NSArray.componentsSeparatedByString(value, ",");
}

But!

I think this is a really lousy idea. For you to be able to go from a string back to your array of serverContracts (and then to their contact.fullNames) you will need to guarantee that the order of the serverContracts array has not changed. I cannot do that, can you? Really. You should try to keep objects as objects for as long as possible, when you reduce them to something flat you lose their identity and then it become really hard to return.

--
;david

--
David LeBer
"I am codeferous!"
Codeferous Software
site:   http://www.codeferous.com
blog: http://david.codeferous.com




_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Set String methods for Flattened Relationship Attributes
      • From: Janice Cheung <email@hidden>
    • Re: Set String methods for Flattened Relationship Attributes
      • From: Arturo Perez <email@hidden>
    • Re: Set String methods for Flattened Relationship Attributes
      • From: Lachlan Deck <email@hidden>
References: 
 >WOMailDelivery Woes - Data Types incorrectly set? (From: Janice Cheung <email@hidden>)
 >Set String methods for Flattened Relationship Attributes (From: Janice Cheung <email@hidden>)
 >Re: Set String methods for Flattened Relationship Attributes (From: David LeBer <email@hidden>)
 >Re: Set String methods for Flattened Relationship Attributes (From: Janice Cheung <email@hidden>)

  • Prev by Date: File Permissions
  • Next by Date: Re: File Permissions
  • Previous by thread: Re: Set String methods for Flattened Relationship Attributes
  • Next by thread: Re: Set String methods for Flattened Relationship Attributes
  • Index(es):
    • Date
    • Thread