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

Setter for 'defaultRegion' is deprecated! #783

Open
3 tasks done
MostafaBelihi opened this issue Jun 25, 2024 · 1 comment
Open
3 tasks done

Setter for 'defaultRegion' is deprecated! #783

MostafaBelihi opened this issue Jun 25, 2024 · 1 comment

Comments

@MostafaBelihi
Copy link

New Issue Checklist

  • Updated PhoneNumberKit to the latest version
  • (NA) Phone number formatted correctly on JavaScript version
  • I searched for existing GitHub issues
  • I am aware that this library is not responsible of adding/removing/changing phone number formats and any request should be done at libphonenumber repo

Steps to reproduce

I'm using the PhoneNumberTextField in a SwiftUI project, so I'm wrapping it in UIViewRepresentable view. This, as I think, prevents the Country Picker View Controller from working. After all, I'm satisfied by just having the textfield and its formatting and validation capabilities.

However, this means that I have to implement a picker for country codes myself using SwiftUI, which I did. Also means that I need to set the picked country code to the PhoneNumberTextField manually.

What I did is to set it like:

let textField = PhoneNumberTextField()
textField.defaultRegion = "FR"
textField.withExamplePlaceholder = true
textField.withFlag = true
textField.withPrefix = true

Until now, it works as I expect, but I get this warning when I use textField.defaultRegion:

Setter for 'defaultRegion' is deprecated:     The setter of defaultRegion is deprecated,
    please override defaultRegion in a subclass instead.

I think that subclassing is not ideal for me in this case, as I need to dynamically set defaultRegion using my picker.

Will this setter be removed in a future release?
I need a sustainable way to safely set this property without any issues.

Environment

Target platform: iOS
Library used via SPM.

@kohenkatz
Copy link

I have a similar use-case (though it is for design reasons, not technical reasons) - our design calls for the country picker and the phone field to be separate fields. We need to call the setter for defaultRegion when the country changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants