• 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: Extending NSMutableDictionary what am I doing wrong?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extending NSMutableDictionary what am I doing wrong?


  • Subject: Re: Extending NSMutableDictionary what am I doing wrong?
  • From: Public Look <email@hidden>
  • Date: Thu, 26 Feb 2004 18:43:58 -0500

I have not been following this thread, but adding -title, and -text methods to NSMutableArray seems like a very odd thing to do. Array's don't have titles or text.

I have to suspect that what is really needed in a new class that contains a mutable array as well as a title and some text. "Has A" relationships are almost always better than "Is A" relationships between classes IMHO.

On Feb 26, 2004, at 2:14 PM, b.bum wrote:

On Feb 26, 2004, at 5:30 AM, Ondra Cada wrote:
Meatime, consider whether a category would be sufficient for the extension you need: if so, just use it. Categories work with class clusters like a charm, and using them is *WAYS* easier than subclassing anyway.

Sort of.

In this case, the developer wants....

- (NSString*)title;
- (NSData*)text;

.... and adding those two methods as a category on NSMutableDictionary will result in every dictionary in the entire runtime responding to those two methods. This will change the behavior of -valueForKey:. If there is any UI element bound to 'text' or 'title' in any piece of UI anywhere in the app -- regardless of whether it was originally a part of the app or a plugin or a part of Cocoa -- those keys will no longer be unbound.

Categories are very powerful and convenient. They are also dangerous.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Extending NSMutableDictionary what am I doing wrong? (From: Ondra Cada <email@hidden>)
 >Re: Extending NSMutableDictionary what am I doing wrong? (From: "b.bum" <email@hidden>)

  • Prev by Date: RE: Accepting url drags directly from safari
  • Next by Date: Re: Checkboxes in an NSTableView
  • Previous by thread: Re: Extending NSMutableDictionary what am I doing wrong?
  • Next by thread: Re: Extending NSMutableDictionary what am I doing wrong?
  • Index(es):
    • Date
    • Thread