google / google/j2objc

New @ObjectiveCConforms annotation

Open
#1,027 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
6k
Forks
999
Avg merge
19h 20m
Merged PRs (30d)
14

Description

[yegor.k wrote on j2objc-discuss](https://groups.google.com/forum/#!topic/j2objc-discuss/DaDjhW4ePtA):

With the existing @ObjectiveCName annotation it is easy for a Java class to implement UIKit protocols, but it's impossible to mark the class as conforming to a given protocol. My suggestion is to use an annotation to specify the list of protocols the translated ObjC class is confirming to, for example:

```
@ObjectiveCConforms("UITextFieldDelegate")
public class MyClass
{
@ObjectiveCName("textFieldDidBeginEditing:")
void textFieldDidBeginEditing(textField: Object)
{
// Do Something
}
}
```

Now, as in the previous case, this is mostly (see below) optional: one can skip protocol specification and cast in assignment, but as with the previous case, this would remove the need for a cast and add ObjC type checking, which is always good.

Also, with such a new annotation, the ObjC "conformsToProtocol:" function will actually work correctly for Java classes; granted, most libraries don't actually check the protocol itself, only checking "respondsToSelector:", but some do (for example, Google Maps SDK is checking for conformance to GMSMapViewDelegate and the delegate won't work if conformity is not declared).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.