• 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: Trapping insert nil value into dictionary?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trapping insert nil value into dictionary?


  • Subject: Re: Trapping insert nil value into dictionary?
  • From: Don Yacktman <email@hidden>
  • Date: Fri, 17 Oct 2003 00:10:34 -0600

On Thursday, October 16, 2003, at 10:59 PM, Ben Kennedy wrote:
On 17 10 2003 at 9:53 pm -0400, Ambroise Confetti wrote:
I've never tried it myself, but you could use +[NSObject poseAsClass:].
Make a subclass of NSCFDictionary that overrides setObject:forKey: and
goes through a piece of code only if the object argument is nil (then
you can break there), and as early as possible in you application's
code, add

[[MyNSCFDictionarySubclass class] poseAsClass:[NSCFDictionary class]];

Thanks for the idea Ambroise. However, I'm having trouble doing this...
because I can't find a definition of NSCFDictionary anywhere. PB of
course complains, because it won't let me subclass what it doesn't know about.

I've grepped /System/Library and /Library for NSCFDictionary and no .h
files are found.

It's a private Foundation Kit class. You'll have to either create your own dummy header to include or use the class-dump program to create one (my preferred approach). To do the latter, download class-dump, since it doesn't come with Mac OS X, and then run it on the binary file inside of Foundation.framework to expose all the private methods and classes. Excerpt the part(s) you need, since it will give you a dump of *everything*.

You can get class-dump here:

http://homepage.mac.com/nygard/Projects/

That should help you get a step or two closer...

I've tried subclassing NSMutableDictionary for the hell of it, and as I
expected, nothing happens (it's not the same class, obviously).

And as you noticed, that often won't work. For the approach Ambroise is suggesting to be effective, you have to subclass and pose as the concrete class that is actually being used, not the class cluster's abstract wrapper class. In this case, the concrete class overrides the methods in the abstract superclass, so your code is being bypassed.

--
Later,

Don Yacktman
email@hidden
_______________________________________________
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.

  • Follow-Ups:
    • Re: Trapping insert nil value into dictionary?
      • From: "Ben Kennedy" <email@hidden>
References: 
 >Re: Trapping insert nil value into dictionary? (From: "Ben Kennedy" <email@hidden>)

  • Prev by Date: Re: Safari and Google-like toolbars
  • Next by Date: Re: Setting Network Preferences Programatically - Part 2
  • Previous by thread: Re: Trapping insert nil value into dictionary?
  • Next by thread: Re: Trapping insert nil value into dictionary?
  • Index(es):
    • Date
    • Thread