[Mono-osx] [MonoMac] NSMutableDictionary FromObjectsAndKeys problem
kjpou
kjpou at pt.lu
Tue Nov 16 00:08:17 EST 2010
Hello Miguel
Yes was running with latest version as of Sunday. Updated this morning
and the problem still existed.
I started looking at it and there are two ways of approaching the
problem that I found.
1) The easiest was the following:
Add the following to foundation.cs for interface NSMutableDictionary
specifying [New]
[Export ("dictionaryWithObjects:forKeys:")]
[Static,New]
NSMutableDictionary FromObjectsAndKeys (NSObject [] objects,
NSObject [] Keys);
*** Note *** If [New] is not specified it will not work correctly
because it uses the base NSDictionary method and the Dictionary returned
is not Mutable.
Also commenting out the following code in NSMutableDictionary.cs
public static NSMutableDictionary FromObjectsAndKeys (NSObject
[] objects, NSObject [] keys)
{
if (objects.Length != keys.Length)
throw new ArgumentException ("objects and keys arrays
have different sizes");
return FromObjectsAndKeys (objects, keys);
}
2) The second approach was keeping the ArgumentException check in
NSMutableDictionary.cs and defining a new internal method in foundation.cs
NSMutableDictionary.cs
public static NSMutableDictionary FromObjectsAndKeys (NSObject
[] objects, NSObject [] keys)
{
if (objects.Length != keys.Length)
throw new ArgumentException ("objects and keys arrays
have different sizes");
return FromObjectsAndKeysInternal (objects, keys);
}
foundation.cs
[Export ("dictionaryWithObjects:forKeys:")]
[Static,Internal]
NSMutableDictionary FromObjectsAndKeysInternal (NSObject []
objects, NSObject [] Keys);
I chose the second approach to keep the ArgumentException check in with
the least amount of changes.
Either one works.
I have attached the diff if you choose the second one.
Shouldn't NSDictionary include the same ArgumentException check as
NSMutableDictionary if that is the way you decide? Just for consistency
if anything.
Kenneth
On 11/16/10 12:47 AM, Miguel de Icaza wrote:
> Hello,
>
>> I am working with a mutable dictionary with bindings to an ArrayController
>> and am having problems creating a NSMutableDictionary using the
>> FromObjectsAndKeys.
> Are you running the latest version from GitHub?
>
> On Friday or so, Geoff fixed an important bug with arrays in the Monomac
> runtime.
>
>> It works for a NSDictionary but not when creating a NSMutableDictionary.
>>
>> The example code below shows what I am talking about.
>>
>> var objects = new NSObject[3] {new NSString("AAAAA"),
>> new NSString("BBBBB"),
>> new NSString("CCCCCC")};
>>
>> var keys = new NSObject[3] {new NSString("firstkey"),
>> new NSString("secondkey"),
>> new NSString("thirdkey")};
>>
>> var dict2 = NSDictionary.FromObjectsAndKeys(objects,keys);
>>
>> //var dict = NSMutableDictionary.FromObjectsAndKeys(objects, keys);
>> var dict = NSMutableDictionary.FromDictionary(dict2);
>>
>> myContentArray.AddObject(dict);
>>
>> The implementation between NSDictionary.cs and NSMutableDictionary.cs are
>> different for that method and not sure why.
>>
>> Any help would be appreciated
>>
>> Kenneth
>>
>> ----------------------------------
>> If you uncomment the //var dict =
>> NSMutableDictionary.FromObjectsAndKeys(objects, keys); it gives the
>> following error:
>>
>> Stacktrace:
>>
>> at (wrapper managed-to-native)
>> MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_int
>> (intptr,intptr,intptr,intptr,int)<0x00004>
>> at (wrapper managed-to-native)
>> MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_int
>> (intptr,intptr,intptr,intptr,int)<0x00004>
>> at MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys
>> (MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[],int)<0x00067>
>> at MonoMac.Foundation.NSMutableDictionary.FromObjectsAndKeys
>> (MonoMac.Foundation.NSObject[],MonoMac.Foundation.NSObject[])<0x00028>
>> at NSTableViewBinding.TestWindowController.AwakeFromNib ()<0x001f8>
>> at (wrapper native-to-managed) object.92f48794-05ff-4e21-bcf0-61c0dd4bf42b
>> (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector)<0x000cc>
>> at (wrapper managed-to-native)
>> MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr)
>> <0x00004>
>> at (wrapper managed-to-native)
>> MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr)
>> <0x00004>
>> at MonoMac.AppKit.NSWindowController.get_Window ()<0x00079>
>> at NSTableViewBinding.TestWindowController.get_Window ()<0x00012>
>> at NSTableViewBinding.AppDelegate.FinishedLaunching
>> (MonoMac.Foundation.NSObject)<0x00038>
>> at (wrapper native-to-managed) object.00860f4e-27a8-4ca0-aa64-ae2828705416
>> (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject)
>> <0x00118>
>> at (wrapper managed-to-native)
>> MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[])<0x00004>
>> at (wrapper managed-to-native)
>> MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[])<0x00004>
>> at MonoMac.AppKit.NSApplication.Main (string[])<0x00015>
>> at NSTableViewBinding.MainClass.Main (string[])<0x00015>
>> at (wrapper runtime-invoke)<Module>.runtime_invoke_void_object
>> (object,intptr,intptr,intptr)<0x00043>
>>
>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nsmutabledictionary.diff
Url: http://lists.ximian.com/pipermail/mono-osx/attachments/20101116/41f14f53/attachment.pl
More information about the Mono-osx
mailing list