New @ObjectiveCType annotation
- 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):
Consider the following code example:
```
public class MyClass
{
Object view;
public native void setAlpha(float alpha)
/*-[
[(UIView*)view_ setAlpha:alpha];
]-*/;
}
```
Obviously this works. But my suggestion is to use an annotation to specify the type to use in ObjC code, for example:
```
public class MyClass
{
@ObjectiveCType("UIView*") Object view;
public native void setNativeAlpha(float alpha, int animate)
/*-[
[view_ setAlpha:alpha];
]-*/;
}
```
This way there is no need to cast in the native code, so the code looks cleaner and there is now type safety on the ObjC side! A win-win.
Contributor guide
Assessment
This issue has not been assessed yet.