A way to get the return type of a method in Objective-C?

I am writing a generic attribute / key representation class in iOS and, for example, checking the type of the editing key using [objectForKey isKindOfClass:[NSDate class]]. I just ran into the wall when I realized that this would happen if objectForKey nil. Is there a way to get the class / return type for a generic Objective-C property, even if the specified property nil? I know about method_getReturnTyperuntime in Objective-C, but that sounds like overkill for what I need.

+3
source share
4 answers

You can not. Although return type information is available for methods, the return type for methods returning objects is simple @, which means "reference to an object."

+3
source

What you are asking for does not make sense.

Remember that only the name does not identify the method. Objects respond to these messages (or not); the method does not exist alone, only as part of an object (or class).

Without an object, you cannot tell from it that a hypothetical message will be returned to the object.

ETA: How can you edit the attributes of something but not have an object to edit to examine its properties? It seems that you have a mistake somewhere else.

I know about method_getReturnTypeObjective-C runtime, but it sounds like redundant for what I need.

. (KVC- @property), , . (@property), property_getAttributes.

+2

, objectForKey!= nil isKindOfClass? , , - .

0

, , nil NSNull, NSObject,

.

!= nil

(NSNull *) object!= [NSNull null]

0

Source: https://habr.com/ru/post/1775909/


All Articles