From 398ca3089fcfb763fec83f9435030245751107ba Mon Sep 17 00:00:00 2001 From: Levey Date: Fri, 15 May 2020 19:07:45 +0800 Subject: [PATCH] support list mode for Objective-C --- Sources/FPNCountry.swift | 2 +- Sources/FPNCountryListViewController.swift | 12 ++++++------ Sources/FPNCountryRepository.swift | 8 +++++--- Sources/FPNTextField.swift | 10 ++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Sources/FPNCountry.swift b/Sources/FPNCountry.swift index cb33c11f..abf84d37 100644 --- a/Sources/FPNCountry.swift +++ b/Sources/FPNCountry.swift @@ -1,6 +1,6 @@ import UIKit -public struct FPNCountry: Equatable { +public class FPNCountry: NSObject { public var code: FPNCountryCode public var name: String diff --git a/Sources/FPNCountryListViewController.swift b/Sources/FPNCountryListViewController.swift index 8cff2594..3e11c595 100644 --- a/Sources/FPNCountryListViewController.swift +++ b/Sources/FPNCountryListViewController.swift @@ -8,12 +8,12 @@ import UIKit -open class FPNCountryListViewController: UITableViewController, UISearchResultsUpdating, UISearchControllerDelegate { + open class FPNCountryListViewController: UITableViewController, UISearchResultsUpdating, UISearchControllerDelegate { - open var repository: FPNCountryRepository? - open var showCountryPhoneCode: Bool = true - open var searchController: UISearchController = UISearchController(searchResultsController: nil) - open var didSelect: ((FPNCountry) -> Void)? + @objc open var repository: FPNCountryRepository? + @objc open var showCountryPhoneCode: Bool = true + @objc open var searchController: UISearchController = UISearchController(searchResultsController: nil) + @objc open var didSelect: ((FPNCountry) -> Void)? var results: [FPNCountry]? @@ -25,7 +25,7 @@ open class FPNCountryListViewController: UITableViewController, UISearchResultsU initSearchBarController() } - open func setup(repository: FPNCountryRepository) { + @objc open func setup(repository: FPNCountryRepository) { self.repository = repository } diff --git a/Sources/FPNCountryRepository.swift b/Sources/FPNCountryRepository.swift index 9f003d8a..129aa377 100644 --- a/Sources/FPNCountryRepository.swift +++ b/Sources/FPNCountryRepository.swift @@ -7,13 +7,15 @@ import Foundation -open class FPNCountryRepository { +open class FPNCountryRepository : NSObject { - open var locale: Locale + open var locale: Locale open var countries: [FPNCountry] = [] public init(locale: Locale = Locale.current) { - self.locale = locale + self.locale = locale + + super.init() countries = getAllCountries() } diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index f6d4e414..df7b7f84 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -34,7 +34,7 @@ open class FPNTextField: UITextField { private var nbPhoneNumber: NBPhoneNumber? private var formatter: NBAsYouTypeFormatter? - open var flagButton: UIButton = UIButton() + @objc open var flagButton: UIButton = UIButton() open override var font: UIFont? { didSet { @@ -59,7 +59,7 @@ open class FPNTextField: UITextField { } } - open var countryRepository = FPNCountryRepository() + @objc open var countryRepository = FPNCountryRepository() open var selectedCountry: FPNCountry? { didSet { @@ -281,6 +281,12 @@ open class FPNTextField: UITextField { setFlag(countryCode: countryCode) } } + + /// Set the country image according to country.code + @objc open func setFlag(country: FPNCountry) { + setFlag(countryCode: country.code) + } + /// Set the country list excluding the provided countries open func setCountries(excluding countries: [FPNCountryCode]) {