-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[pigeon] Adds @SwiftClass annotation #6372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@LouiseHsu Do you also need the ability to add the |
Yes, that would be helpful! <3 |
For api classes and data classes? or just data classes? |
I think just data classes will be good for now :) |
|
Might be best to combine the two annotations (the inheritance being optional within the class one) |
Done. @stuartmorgan I'm hoping we can push this through in the morning, if you have time to review it. |
packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h
Outdated
Show resolved
Hide resolved
…s into swift-struct-to-class
hellohuanlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of using annotation, because it can get complicated to detect recursive definition and decide struct vs class for developers.
| String inheritNSObject = ''; | ||
| if (classDefinition.isSwiftObjcInteropClass) { | ||
| inheritNSObject = ': NSObject'; | ||
| indent.writeln('@objc'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iirc @objc isn't necessary since it's already a subclass of NSObject, which is already exposed to objc runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry i missed it in my previous review - in addition to the above, we probably need to add @objc for all custom members that are not inherited from NSObject (basically all the properties and the init function defined here).
Can you also write some ObjC tests to make sure it works? (requesting changes since this is not tested)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all properties? even primitives? or only custom types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All properties and methods that are not inherited from NSObject need to be annotated, in order for them to be accessible by objc runtime. The class definition itself and its members inherited from NSObject are already implicitly annotated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yes, even the properties of primitive types.
| String inheritNSObject = ''; | ||
| if (classDefinition.isSwiftObjcInteropClass) { | ||
| inheritNSObject = ': NSObject'; | ||
| indent.writeln('@objc'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry i missed it in my previous review - in addition to the above, we probably need to add @objc for all custom members that are not inherited from NSObject (basically all the properties and the init function defined here).
Can you also write some ObjC tests to make sure it works? (requesting changes since this is not tested)
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once @hellohuanlin's concerns are addressed. (Marking now since I'll be OOO.)
|
@hellohuanlin I removed the @objc feature for now to unblock this pr. I'll throw up a new pr with just that in a short while. |
hellohuanlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, feel free to land this first and create a separate PR for objc interop.
|
Landing to fix the tree |
flutter/packages@28d126c...ab1630b 2024-03-26 tarrinneal@gmail.com [pigeon] Adds @SwiftClass annotation (flutter/packages#6372) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Adds annotation for @SwiftClass which will cause the swift generator to create a
classinstead of astructin the generated Swift code.This will allow for recursive classes as well as allow for Objc interop, without forcing users to lose the potential benefits of structs if they prefer them instead.
Also creates recursive data class integration test to check for coverage on all languages.
fixes flutter/flutter#145175
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.