• 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: Cocoa binding always produces zero for bound value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa binding always produces zero for bound value


  • Subject: Re: Cocoa binding always produces zero for bound value
  • From: Tron Thomas <email@hidden>
  • Date: Mon, 24 Mar 2008 20:48:17 -0700

Ken Thomases wrote:
On Mar 23, 2008, at 8:18 PM, Tron Thomas wrote:

At this point, the compiler only knows that object is an id. It doesn't know the specific class. So, of any of the "value" methods it might know about, it doesn't know which specific one is meant. Normally that wouldn't matter, but when you're dealing with float returns (or struct returns) the generated code would be different.

In other words, the compiler is generating the code here as though it were invoking a "value" method that returns an int. What is actually being invoked is a method which returns a float. The mismatch causes the problem.
The problem is even though the value is updated to some non-zero value, the observed value is always zero. I have tried stepping through the code and verified that when I step into [AnotherObject value] method from the call in [SomeObject observeValueForKeyPath:ofObject:change:context:], the _value instance member is non-zero. Yet when I return to the calling method, the local value variable gets set to zero. This does not make sense.


What would allow the SomeObject instance to get the proper value for AnotherObject when observing it?

There are two approaches to fixing this:

1) Use a method name which won't be ambiguous about its return type, such as floatValue. It's not the name that actually matters, it's that all of the "floatValue" methods that the compiler might know about at that point have a return type of float -- because what perverse soul would create a floatValue method that returned something other than float -- so there's no chance of confusion.

2) Cast "object" to the specific class that you know it to be (i.e. AnotherObject*). You would have to make sure you've imported AnotherObject.h, of course.

Cheers,
Ken


Using a type cast solved the problem. Thanks Ken.

_______________________________________________

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: 
 >Cocoa binding always produces zero for bound value (From: Tron Thomas <email@hidden>)
 >Re: Cocoa binding always produces zero for bound value (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Cocoa Database Connection
  • Next by Date: outlineViewSelectionDidChange not called
  • Previous by thread: Re: Cocoa binding always produces zero for bound value
  • Next by thread: CARenderer Memory Issue
  • Index(es):
    • Date
    • Thread