marmelroy / PhoneNumberKit

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
MIT License
5.1k stars 810 forks source link

Setter for 'defaultRegion' is deprecated! #783

Open MostafaBelihi opened 2 months ago

MostafaBelihi commented 2 months ago

New Issue Checklist

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 commented 1 month ago

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.