Skip to content
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

[swift] add 'has<ArrayName>' property to check optional array presence in mes… #7280

Merged
merged 1 commit into from
May 11, 2022
Merged

Conversation

mr-swifter
Copy link
Contributor

Hello,

I came across issue #7270 and found it would be a very useful feature. It is a pull request to fix the issue.

Exist property added to generation of Swift code.

The change is tested manually in all variants: no vector (property returns false), empty vector (property returns true, count returns 0) and non-empty vector (property returns true, count returns number of items).

@google-cla
Copy link

google-cla bot commented Apr 28, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@github-actions github-actions bot added c++ codegen Involving generating code from schema swift labels Apr 28, 2022
@mustiikhalil
Copy link
Collaborator

mustiikhalil commented Apr 28, 2022

@mr-swifter Thanks for opening the PR.

  • Can you rename it to be similar to how apple has their variables: has{{NAME_FIELD}}

  • Can you add test cases where you cover the following cases, you will need to regenerate the code:
    - Add a vector with items in it, so the results will be hasIntVector = true, count = 1
    - Add a vector with no items in it, so the results will be hasIntVector = true, count = 0
    - Do not serialize a vector, and the results will be hasIntVector = false, count = 0

@mr-swifter
Copy link
Contributor Author

@mustiikhalil , thanks for feedback, I renamed the property and added unit test.

@mr-swifter mr-swifter changed the title [swift] add '*Exist' property to check optional array presence in mes… [swift] add 'has<ArrayName>' property to check optional array presence in mes… Apr 29, 2022
@mustiikhalil
Copy link
Collaborator

@mr-swifter looks good, however you will need to:
1- Run the code generation to add this to all the generated codes. Check Scripts and add this file to it, and also add it to SwiftTests.sh
2- Sign the CLA

@mr-swifter
Copy link
Contributor Author

@mustiikhalil , thanks for guiding me through that. points 1 and 2 are done, squashed to a single commit for convenience.

@mustiikhalil
Copy link
Collaborator

@mr-swifter sorry was a bit under the weather lately, looked at the PR looks good. But I think I kinda didn't explain myself in a better way earlier, we need to add the generated code to the python script too linked here. I think just adding it like what's mentioned below would be good

flatc(SWIFT_OPTS, schema="optional_scalars.fbs", prefix=swift_prefix)
flatc(SWIFT_OPTS, schema="vector_has_test.fbs", prefix=swift_prefix) // new

@mr-swifter
Copy link
Contributor Author

Aha, got you now, let me add this.

@github-actions github-actions bot added the python label May 4, 2022
@mr-swifter
Copy link
Contributor Author

@mustiikhalil, done! generate_code.py changes a bit generated swift code, so I also committed this to make sure check_generate_code.py gives no diff.

@mustiikhalil
Copy link
Collaborator

@mr-swifter can you rebase master and force push again. it seems that the android CI is acting up

@mr-swifter
Copy link
Contributor Author

mr-swifter commented May 5, 2022

Sure, I can do it, but as I can see CI / Build Android is failing on main branch as well, so seems rebase will not help. Or do I miss something?

@mustiikhalil
Copy link
Collaborator

Yeah its failing on master but if you see this #7293 pr, you would see that they are passing.

@mustiikhalil mustiikhalil merged commit 1ea2472 into google:master May 11, 2022
@mustiikhalil
Copy link
Collaborator

@mr-swifter Thanks!

@mr-swifter
Copy link
Contributor Author

Thanks for help @mustiikhalil! Sorry didn't complete rebase, I was on holidays, but see you merged it, thanks!

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sssooonnnggg pushed a commit to sssooonnnggg/flatbuffers that referenced this pull request Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema python swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants