Does Objective-C have an equivalent to java annotations?

前端 未结 8 1110
后悔当初
后悔当初 2020-12-28 09:10

Does Objective-C have an equivalent to java annotations?

What\'s I\'m trying to do is create a property and be able to somehow access some metadata about it.

8条回答
  •  心在旅途
    2020-12-28 09:32

    I expect it should be clear now, the answer is NO, not at the moment.

    Some people found some alternatives which seem to work in their specific use cases.

    But in general there is no comparable feature yet in objective-c. IMHO clang metadata seems to provide a good foundations for this, but as long as there is not support from Apple this will not help, as far as i understood it.

    Btw. I guess it should be clear, but just to repeat for all: two changes are required to support annotations as provided in java.

    1. The language need an extension the annotate e.g. methodes, properites, classes, ... in the source code.
    2. A standard interface is required to access the annotated information. This can only provide by apple.

    Most alternativ soltuions move the annotation information into runtime and define their own interface. The objective-c runtime provide a standard interface but only with some trick you can annotate properties and still the isse of runtime population.

    The typical use case for suche a feature is an IOC container (in Java e.g. Spring) which use the annotated information to inject other objects.

    I would suggest to open an feature requrest for Apple to support this.

提交回复
热议问题