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

Fix delay of FPNCountry initialisation #149

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions Sources/FPNCountry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ import UIKit

public struct FPNCountry: Equatable {

public var code: FPNCountryCode
public var code: FPNCountryCode {
get {
FPNCountryCode(rawValue: self.codeStr)!
}
}
private var codeStr: String
public var name: String
public var phoneCode: String
var flag: UIImage?
var flag: UIImage? {
get {
if let flag = UIImage(named: self.codeStr, in: Bundle.FlagIcons, compatibleWith: nil) {
return flag
} else {
return UIImage(named: "unknown", in: Bundle.FlagIcons, compatibleWith: nil)
}
}
}

init(code: String, name: String, phoneCode: String) {
self.name = name
self.phoneCode = phoneCode
self.code = FPNCountryCode(rawValue: code)!

if let flag = UIImage(named: code, in: Bundle.FlagIcons, compatibleWith: nil) {
self.flag = flag
} else {
self.flag = UIImage(named: "unknown", in: Bundle.FlagIcons, compatibleWith: nil)
}
self.codeStr = code
}

static public func ==(lhs: FPNCountry, rhs: FPNCountry) -> Bool {
static public func == (lhs: FPNCountry, rhs: FPNCountry) -> Bool {
return lhs.code == rhs.code
}
}