Bug 3995 - Binding NSComparator to Delegate Problem: return value not bound?
Summary: Binding NSComparator to Delegate Problem: return value not bound?
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-03-20 17:11 UTC by Marcus Wilhelm
Modified: 2012-03-21 09:51 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Marcus Wilhelm 2012-03-20 17:11:07 UTC
Hi,

I try to bind the following objc method (from the Sparrow Framework):

    - (void)sortChildren:(NSComparator)comparator;

To do so, I have defined a delegate like this:

    public delegate int SPDisplayObjectComparator(SPDisplayObject obj1, SPDisplayObject obj2);

And a binding method:

    [Export("sortChildren:")]
    void Sort(SPDisplayObjectComparator comparator);

Example usage:

    container.Sort(delegate(SPDisplayObject o1, SPDisplayObject o2) {
        return o1.Name.CompareTo(o2.Name);
    });

My delegate gets called fine but the sorting result is wrong, so I looked into the generated binding code and it seems that my return value is ignored and never passed to objc.

I am really new to the objc binding stuff so maybe it isn't a bug. Can you verify this? If you want to have a look into my complete binding code you can do it here: https://github.com/goosefx/sparrow-monotouch

The respective class is SPDisplayObjectContainer, a test for my binding is inside the UnitTests project Tests/SPDisplayObjectContainer 

regards
Marcus
Comment 1 Sebastien Pouliot 2012-03-20 20:42:38 UTC
You're right (good catch!). The return value form the delegate is ignored by the generated code. It seems there's only a single case where we have bindings using a non-void delegate (I'll check to see if it works / generate different code).

note: I tried this on a smaller test case, binding/testing NSArray's sortedArrayUsingComparator:
Comment 2 Sebastien Pouliot 2012-03-20 21:12:32 UTC
testing a patch...
Comment 3 Sebastien Pouliot 2012-03-21 09:47:14 UTC
Fixed in master 2454042709f9ad1da50c4b2e40c9c712ebf1cb47
and 5.2-series a63218aa067bdd7fb3f73463afbb466663b4a10f

QA: unit tests in master
Comment 4 Marcus Wilhelm 2012-03-21 09:51:33 UTC
+1 That was fast. Thanks!