English 中文(简体)
如何宣布符合议定书的类别为参数类型?
原标题:How to declare a class that conforms to a protocol as parameter type?

是否有办法将符合某一议定书的类别作为参数?

首先,抱着希望,我尝试的是:

-(NSString *) getKeyForMyProtocolClass(Class<MyProtocol>)aClass

但是,造成这种情况的原因是:

[aClass superclass];

发出警告:“发现的超级方法,而不是等级方法超级”。 我收到同样警告,要求遵守。 议定书:

Since it gives no such warnings when the parameter is (Class)aClass, it seems Class< MyProtocol> is not actually of the Class type.

我不应寄出NSObject < My Protocol>因为我需要根据类别及其超级类别确定正确的钥匙,并且只有在对钥匙没有规定的情况下,才产生和添加新的物体。

我可以检查是否符合规定。 对《议定书》而言,但随后我不得不回去一点价值,这只是表面的。 我倾向于在汇编时间停止这一问题。

因此,简言之,是否对符合议定书的一类类别作出声明?

问题回答

你可以简单地勾画你的班子,以防止汇编者发出警告。 我能够做以下工作:

- (void)tempMethod:(Class<NSObject>)klass {
   id a = [(Class)klass superclass];
    NSLog(@"%@", a);
}

Since you know the type of the object(Class object) you re passing this should work fine.





相关问题
asp.net cookie from a resource project (+ a general info)

i d like to use a class to manage a certain cookie, but not directly on the page where i have access to all the httpcookie stuff like so HttpContext.Current.Request.Cookies["CookieName"].Value;. ...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

Creating (boxed) primitive instance when the class is known

I need a method that returns an instance of the supplied class type. Let s assume that the supplied types are limited to such that an "empty" instance of them can be created. For instance, supplying ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

C# Class Definition

In XCode and objective c, if I want to use a UIGlassButton in interface builder, I put the following line in my header file: @class UIGlassButton; I am now using monotouch c#. Is there a similar ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

热门标签