PhoneNumberKit icon indicating copy to clipboard operation
PhoneNumberKit copied to clipboard

Setter for 'defaultRegion' is deprecated!

Open MostafaBelihi opened this issue 7 months ago • 1 comments

New Issue Checklist

  • [x] Updated PhoneNumberKit to the latest version
  • (NA) Phone number formatted correctly on JavaScript version
  • [x] I searched for existing GitHub issues
  • [x] 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.

MostafaBelihi avatar Jun 25 '24 16:06 MostafaBelihi