• 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: Using runtime functions to match up object types safely when setting properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using runtime functions to match up object types safely when setting properties


  • Subject: Re: Using runtime functions to match up object types safely when setting properties
  • From: Andrew Farmer <email@hidden>
  • Date: Sat, 20 Dec 2008 21:34:25 -0800

On 20 Dec 08, at 02:16, Graham Cox wrote:
On 20 Dec 2008, at 8:05 pm, Andrew Farmer wrote:
However, I think you've overengineering things here. The standard runtime introspection methods, like [NSObject class] and [NSObject isKindOfClass:], should be more than enough to implement this sort of functionality.

You might be right about the overengineering, but -class and - isKindOfClass: can't be used on methods, only on objects you already have. If you have an object that has a property setter, e.g.


- (void)    setColor:(NSColor*) aColor;

and you have a variable selector that can refer to that (but also potentially many other) methods, and an object that might, or might not, be an NSColor*, how do you make sure you don't end up sending that method a string?

Ah... I probably should have explained further. What I was thinking of was a "try first and ask forgiveness" approach - have the calling code attempt to set the property unconditionally, and have the setter throw an exception if the object it's passed is in fact of the wrong type. This isn't any help if you need to *determine* what the desired type is, but it's fine if all you need to be able to do is throw an error when the wrong type of object is passed.
_______________________________________________


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


References: 
 >Using runtime functions to match up object types safely when setting properties (From: Graham Cox <email@hidden>)
 >Re: Using runtime functions to match up object types safely when setting properties (From: Ken Thomases <email@hidden>)
 >Re: Using runtime functions to match up object types safely when setting properties (From: Andrew Farmer <email@hidden>)
 >Re: Using runtime functions to match up object types safely when setting properties (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Copying Managed Objects from App to Doc MOContext
  • Next by Date: Re: selectionShouldChangeInTableView called twice
  • Previous by thread: Re: Using runtime functions to match up object types safely when setting properties
  • Next by thread: Sorting an NSMutableArray
  • Index(es):
    • Date
    • Thread