我是Monotouch的新手。最近,我正在研究一个Monotouch绑定项目,该项目绑定了一个将自己开发为.NET框架库的自定义iOS框架。我按照Xamarin的说明,但目前我遇到了无法解决的问题。这是我的代码。Monotouch绑定 - “不能从源类型转换为目标类型。”
**HEADER FILE IN OBJECTIVE C**
*GRG.h*
@interface GRG: NSObject {}
// Shared instance
+ (GRG*) sharedG;
// Preference class
@property (nonatomic, readonly) GRGPreferences *preferences;
// Driver version
@property (readonly,copy) NSString* driverVersion;
// More parameters...
@end
*GRGPreferences.h*
@interface GRGPreferences : NSObject <GRGPreferencesProtocol>{}
// Enable DEBUG
@property BOOL debugEnabled;
// More parameters...
@end
*GRGPreferencesProtocol.h*
@protocol GRGPreferencesProtocol <NSObject>
// More parameters...
@end
将我的头文件到这个
**API DEFINITION**
[BaseType (typeof (NSObject))]
interface GRG
{
[Static][Export("sharedG")]
GRG SharedG{ get; }
[Export("preferences")]
GRGPreferences Preferences{ get;}
[Export("driverVersion", ArgumentSemantic.Copy)]
string DriverVersion {get;}
}
[BaseType (typeof (GRGPreferencesProtocol))]
public interface GRGPreferences
{
[Export("debugEnabled")]
bool DebugEnabled{ get; set;}
}
[BaseType(typeof (NSObject))]
[Model]
public interface GRGPreferencesProtocol
{}
在那之后,我创建了单一个测试应用程序测试新创建的库并访问我创造的价值。但是,我得到了一个错误。
Console.WriteLine(GRG.sharedG.DriverVersion); - 这工作正常。它返回适当的值。
GRGPreferences pref = GRG.SharedG.Preferences; - 错误:“无法从源类型转换为目标类型”。
Console.WriteLine(GRG.sharedG.Preferences.DebugEnabled); - 错误:“无法从源类型转换为目标类型”。
任何人都可以帮我吗?
你有没有找到解决这个问题的方法?我有一个非常类似的问题(http://stackoverflow.com/questions/16906955/binding-a-return-type-that-conforms-to-a-protocol) –