Something like Java annotations in Objective-C

I am looking for something like Java annotations (a way to mark a field or method with metadata) in Objective-c, but I cannot find anything that really is a surrogate for this Java function.

Is there a way to achieve the same Java annotation result in Objective-C?

Basically in a real situation, I'm trying to mark some fields in a class that I want to export using a serializer, I want to mark all fields in a class that need to be exported or serialized ...

Is there any other way to mark these fields?

+4
source share
3 answers

I think you're probably looking for: ObjectiveCAnnotate

+3
source

Officially, Objective-C lacks annotation support similar to Java. But to achieve this, a workaround is possible. Use formatted comments as an annotation, then write a parser to parse these annotation comments and save them as a file from which you can read annotations at runtime.

I implemented a project called ROAnnotation that uses this method to provide annotation of the Java time pair value for the Java class in the class / method / property for Objective-C. I think this is what you need.

ROAnnotation on GitHub

+2
source

The most common way to provide metadata about a class (and its instances) seems to be to provide a class method that returns information.

In your case, an array with property names for serialization, for example.

+1
source

All Articles