Monotouch:将对象转换为 NSObject [英] Monotouch: convert an Object to NSObject

查看:60
本文介绍了Monotouch:将对象转换为 NSObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Object 实例转换为 NSObject 实例?

How is it possible to convert an Object instance to NSObject one?

我从

NSDictionary.FromObjectAndKey();

此方法需要一个 NSObject 但我有自定义对象要传入:

This method wants an NSObject but I have custom object to pass in:

int key = 2341;
var val = new MyClass();
NSDictionary.FromObjectAndKey(val, key); // obviously it does not work!!

如何解决这个问题?提前致谢.

How to fix this? Thank you in advance.

推荐答案

您不能将任意对象转换为 NSObject.NSObject.FromObject 将尝试将常见数据类型(如数字、字符串、矩形、点、变换和少数其他 .NET 类型)包装到它们的等效 NSObject 类型中.

You can not convert an arbitrary object into an NSObject. The NSObject.FromObject will try to wrap common data types like numbers, strings, rectangles, points, transforms, and a handful of other .NET types into their equivalent NSObject types.

在您的特定示例中,MyClass"必须从 NSObject 派生,然后才能在 NSDictionary 中使用它.

In your particular example, "MyClass" would have to derive from an NSObject before you could use it in the NSDictionary.

这篇关于Monotouch:将对象转换为 NSObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆