Skip to content

Conversation

@tarrinneal
Copy link
Contributor

Adds annotation for @SwiftClass which will cause the swift generator to create a class instead of a struct in 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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@tarrinneal
Copy link
Contributor Author

@LouiseHsu Do you also need the ability to add the @objc attribute to generated classes?

@LouiseHsu
Copy link
Contributor

LouiseHsu commented Mar 21, 2024

@LouiseHsu Do you also need the ability to add the @objc attribute to generated classes?

Yes, that would be helpful! <3

@tarrinneal
Copy link
Contributor Author

@LouiseHsu Do you also need the ability to add the @objc attribute to generated classes?

Yes, that would be helpful! <3

For api classes and data classes? or just data classes?

@LouiseHsu
Copy link
Contributor

@LouiseHsu Do you also need the ability to add the @objc attribute to generated classes?

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 :)

@tarrinneal
Copy link
Contributor Author

Might be best to combine the two annotations (the inheritance being optional within the class one)

@tarrinneal
Copy link
Contributor Author

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.

Copy link
Contributor

@hellohuanlin hellohuanlin left a 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');
Copy link
Contributor

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.

Copy link
Contributor

@hellohuanlin hellohuanlin Mar 23, 2024

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)

Copy link
Contributor Author

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?

Copy link
Contributor

@hellohuanlin hellohuanlin Mar 24, 2024

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.

Copy link
Contributor

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');
Copy link
Contributor

@hellohuanlin hellohuanlin Mar 23, 2024

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)

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a 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.)

@tarrinneal
Copy link
Contributor Author

@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.

@tarrinneal tarrinneal requested a review from hellohuanlin March 26, 2024 00:18
Copy link
Contributor

@hellohuanlin hellohuanlin left a 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.

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 26, 2024
@tarrinneal
Copy link
Contributor Author

Landing to fix the tree

@tarrinneal tarrinneal merged commit ab1630b into flutter:main Mar 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 26, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 26, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pigeon] Generated swift code throws compile time error on recursive types

4 participants