From ed867ff0afea5e91875b28d6e917db22908bfb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 13 Jan 2017 16:59:37 +0100 Subject: [PATCH 1/5] Localization wip --- Permission.podspec | 1 + Permission.xcodeproj/project.pbxproj | 7 ++++ .../en.lproj/Localizable.strings | 36 +++++++++++++++++++ .../fr.lproj/Localizable.strings | 36 +++++++++++++++++++ Source/PermissionAlert.swift | 22 ++++++------ Source/Supporting Files/Utilities.swift | 11 ++++++ 6 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 Source/Permission.bundle/en.lproj/Localizable.strings create mode 100644 Source/Permission.bundle/fr.lproj/Localizable.strings diff --git a/Permission.podspec b/Permission.podspec index bc52ff5..daf1db5 100644 --- a/Permission.podspec +++ b/Permission.podspec @@ -17,6 +17,7 @@ Pod::Spec.new do |s| s.subspec 'Core' do |co| co.source_files = "Source/**/*.{swift, h}" + co.resources = "Source/Permission.bundle" end s.subspec 'AddressBook' do |ab| diff --git a/Permission.xcodeproj/project.pbxproj b/Permission.xcodeproj/project.pbxproj index df14805..8d3095a 100644 --- a/Permission.xcodeproj/project.pbxproj +++ b/Permission.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 3D42A7DB1D5F66B300236ABA /* SpeechRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D42A7DA1D5F66B300236ABA /* SpeechRecognizer.swift */; }; 3DC217D31D6EFD4A00600DFE /* MediaLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC217D21D6EFD4A00600DFE /* MediaLibrary.swift */; }; + 5641D9AA1E292FB20010AF89 /* Permission.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 5641D9A91E292FB20010AF89 /* Permission.bundle */; }; 6C04FAF61CCA8F3A00B3F361 /* AddressBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C04FAF51CCA8F3A00B3F361 /* AddressBook.swift */; }; 6D0069B41C1868E8002FDB42 /* PermissionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0069B31C1868E8002FDB42 /* PermissionSet.swift */; }; 6D0EBDBD1BFCF8B700C35F8E /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D0EBDBC1BFCF8B700C35F8E /* Utilities.swift */; }; @@ -47,6 +48,7 @@ /* Begin PBXFileReference section */ 3D42A7DA1D5F66B300236ABA /* SpeechRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeechRecognizer.swift; sourceTree = ""; }; 3DC217D21D6EFD4A00600DFE /* MediaLibrary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaLibrary.swift; sourceTree = ""; }; + 5641D9A91E292FB20010AF89 /* Permission.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Permission.bundle; sourceTree = ""; }; 6C04FAF51CCA8F3A00B3F361 /* AddressBook.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddressBook.swift; sourceTree = ""; }; 6D0069B31C1868E8002FDB42 /* PermissionSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PermissionSet.swift; sourceTree = ""; }; 6D0EBDBC1BFCF8B700C35F8E /* Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; @@ -124,6 +126,7 @@ 6D0069B31C1868E8002FDB42 /* PermissionSet.swift */, 6D491E771C9CA90B00611006 /* PermissionStatus.swift */, 6D491E751C9CA7DE00611006 /* PermissionType.swift */, + 5641D9A91E292FB20010AF89 /* Permission.bundle */, ); path = Source; sourceTree = ""; @@ -254,6 +257,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + fr, ); mainGroup = 6D86A9A81BEBDC7C00E3DD5A; productRefGroup = 6D86A9B31BEBDC7D00E3DD5A /* Products */; @@ -271,6 +275,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5641D9AA1E292FB20010AF89 /* Permission.bundle in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -337,6 +342,7 @@ baseConfigurationReference = D08FF2891DC3AD2900F28088 /* PermissionFlags.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -389,6 +395,7 @@ baseConfigurationReference = D08FF2891DC3AD2900F28088 /* PermissionFlags.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; diff --git a/Source/Permission.bundle/en.lproj/Localizable.strings b/Source/Permission.bundle/en.lproj/Localizable.strings new file mode 100644 index 0000000..6ea55ef --- /dev/null +++ b/Source/Permission.bundle/en.lproj/Localizable.strings @@ -0,0 +1,36 @@ +/* + Localizable.strings + Permission + + Created by Gwendal Roué on 13/01/2017. + Copyright © 2017 delba. All rights reserved. +*/ + +"OK" = "OK"; +"Cancel" = "Cancel"; +"Settings" = "Settings"; +"Confirm" = "Confirm"; + +"Location is currently disabled" = "Location is currently disabled"; +"Permission for Location was denied" = "Permission for your location was denied"; +"Please enable access to Location in the Settings app." = "Please enable access to your location in the Settings app."; +"%@ would like to access your Location" = "%@ would like to access your location"; +"Please enable access to Location." = "Please enable access to your location."; + +"Motion is currently disabled" = "Motion is currently disabled"; +"Permission for Motion was denied" = "Permission to access your motions was denied"; +"Please enable access to Motion in the Settings app." = "Please enable access to your motions in the Settings app."; +"%@ would like to access your Motion" = "%@ would like to access your motions"; +"Please enable access to Motion." = "Please enable access to your motions."; + +"Notifications is currently disabled" = "Notifications is currently disabled"; +"Permission for Notifications was denied" = "Permission for notifications was denied"; +"Please enable access to Notifications in the Settings app." = "Please enable notifications in the Settings app."; +"%@ would like to access your Notifications" = "%@ would like to display notifications"; +"Please enable access to Notifications." = "Please allow notifications."; + +"Bluetooth is currently disabled" = "Bluetooth is currently disabled"; +"Permission for Bluetooth was denied" = "Permission for Bluetooth was denied"; +"Please enable access to Bluetooth in the Settings app." = "Please enable Bluetooth in the Settings app."; +"%@ would like to access your Bluetooth" = "%@ would like to use Bluetooth"; +"Please enable access to Bluetooth." = "Please enable Bluetooth."; diff --git a/Source/Permission.bundle/fr.lproj/Localizable.strings b/Source/Permission.bundle/fr.lproj/Localizable.strings new file mode 100644 index 0000000..70f1221 --- /dev/null +++ b/Source/Permission.bundle/fr.lproj/Localizable.strings @@ -0,0 +1,36 @@ +/* + Localizable.strings + Permission + + Created by Gwendal Roué on 13/01/2017. + Copyright © 2017 delba. All rights reserved. +*/ + +"OK" = "OK"; +"Cancel" = "Annuler"; +"Settings" = "Réglages"; +"Confirm" = "OK"; + +"Location is currently disabled" = "L’accès à votre position est désactivé"; +"Permission for Location was denied" = "L’accès à votre position est refusé."; +"Please enable access to Location in the Settings app." = "Veuillez autoriser l'accès à votre position dans l’application Réglages."; +"%@ would like to access your Location" = "%@ voudrait accéder à votre position"; +"Please enable access to Location." = "Veuillez autoriser l'accès à votre position."; + +"Motion is currently disabled" = "L’accès à vos mouvements est désactivé"; +"Permission for Motion was denied" = "L’accès à vos mouvements est refusé."; +"Please enable access to Motion in the Settings app." = "Veuillez autoriser l'accès à vos mouvements dans l’application Réglages."; +"%@ would like to access your Motion" = "%@ voudrait accéder à vos mouvements"; +"Please enable access to Motion." = "Veuillez autoriser l'accès à vos mouvements."; + +"Notifications is currently disabled" = "Les notifications sont désactivées"; +"Permission for Notifications was denied" = "Les notifications sont désactivées"; +"Please enable access to Notifications in the Settings app." = "Veuillez accepter les notifications dans l’application Réglages."; +"%@ would like to access your Notifications" = "%@ voudrait vous envoyer des notifications"; +"Please enable access to Notifications." = "Veuillez accepter les notifications."; + +"Bluetooth is currently disabled" = "L’accès à Bluetooth est désactivé"; +"Permission for Bluetooth was denied" = "L’accès à Bluetooth est refusé."; +"Please enable access to Bluetooth in the Settings app." = "Veuillez activer Bluetooth dans l’application Réglages."; +"%@ would like to access your Bluetooth" = "%@ voudrait utiliser Bluetooth"; +"Please enable access to Bluetooth." = "Veuillez activer Bluetooth."; diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index 01cd2c0..4c6fbc2 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -89,9 +89,9 @@ internal class DisabledAlert: PermissionAlert { override init(permission: Permission) { super.init(permission: permission) - title = "\(permission) is currently disabled" - message = "Please enable access to \(permission) in the Settings app." - cancel = "OK" + title = "\(permission) is currently disabled".localized() + message = "Please enable access to \(permission) in the Settings app.".localized() + cancel = "OK".localized() } } @@ -112,10 +112,10 @@ internal class DeniedAlert: PermissionAlert { override init(permission: Permission) { super.init(permission: permission) - title = "Permission for \(permission) was denied" - message = "Please enable access to \(permission) in the Settings app." - cancel = "Cancel" - settings = "Settings" + title = "Permission for \(permission) was denied".localized() + message = "Please enable access to \(permission) in the Settings app.".localized() + cancel = "Cancel".localized() + settings = "Settings".localized() } @objc func settingsHandler() { @@ -149,10 +149,10 @@ internal class PrePermissionAlert: PermissionAlert { override init(permission: Permission) { super.init(permission: permission) - title = "\(Bundle.main.name) would like to access your \(permission)" - message = "Please enable access to \(permission)." - cancel = "Cancel" - confirm = "Confirm" + title = String(format: "%@ would like to access your \(permission)".localized(), Bundle.main.name) + message = "Please enable access to \(permission).".localized() + cancel = "Cancel".localized() + confirm = "Confirm".localized() } fileprivate func confirmHandler(_ action: UIAlertAction) { diff --git a/Source/Supporting Files/Utilities.swift b/Source/Supporting Files/Utilities.swift index fe59323..498672a 100644 --- a/Source/Supporting Files/Utilities.swift +++ b/Source/Supporting Files/Utilities.swift @@ -65,6 +65,17 @@ internal extension String { static let stateBluetoothManagerDetermined = "permission.stateBluetoothManagerDetermined" } +let permissionBundle: Bundle = { + let path = Bundle(for: Permission.self).path(forResource: "Permission", ofType: "bundle")! + return Bundle(path: path)! +}() + +internal extension String { + func localized() -> String { + return NSLocalizedString(self, tableName: "Localizable", bundle: permissionBundle, value: self, comment: "") + } +} + internal extension Selector { static let tapped = #selector(PermissionButton.tapped(_:)) static let highlight = #selector(PermissionButton.highlight(_:)) From 6b779dfeff4ea435099efc29b37f98208a581598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 13 Jan 2017 17:05:54 +0100 Subject: [PATCH 2/5] Localization wip --- Source/Permission.bundle/fr.lproj/Localizable.strings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Permission.bundle/fr.lproj/Localizable.strings b/Source/Permission.bundle/fr.lproj/Localizable.strings index 70f1221..00eca55 100644 --- a/Source/Permission.bundle/fr.lproj/Localizable.strings +++ b/Source/Permission.bundle/fr.lproj/Localizable.strings @@ -29,7 +29,7 @@ "%@ would like to access your Notifications" = "%@ voudrait vous envoyer des notifications"; "Please enable access to Notifications." = "Veuillez accepter les notifications."; -"Bluetooth is currently disabled" = "L’accès à Bluetooth est désactivé"; +"Bluetooth is currently disabled" = "Bluetooth est désactivé"; "Permission for Bluetooth was denied" = "L’accès à Bluetooth est refusé."; "Please enable access to Bluetooth in the Settings app." = "Veuillez activer Bluetooth dans l’application Réglages."; "%@ would like to access your Bluetooth" = "%@ voudrait utiliser Bluetooth"; From fbb4a239dbd0c4aa79710ab552808e1c9a4e9777 Mon Sep 17 00:00:00 2001 From: Yaroslav Erohin Date: Sun, 15 Jan 2017 15:34:51 +0300 Subject: [PATCH 3/5] Partial russian localization Translated for: Location, Motion, Notifications, Bluetooth, Photos --- .../ru.lproj/Localizable.strings | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Source/Permission.bundle/ru.lproj/Localizable.strings diff --git a/Source/Permission.bundle/ru.lproj/Localizable.strings b/Source/Permission.bundle/ru.lproj/Localizable.strings new file mode 100644 index 0000000..7e0e576 --- /dev/null +++ b/Source/Permission.bundle/ru.lproj/Localizable.strings @@ -0,0 +1,42 @@ +/* + Localizable.strings + Permission + + Created by Yaroslav Erohin on 15/01/2017. + Copyright © 2017 delba. All rights reserved. +*/ + +"OK" = "ОК"; +"Cancel" = "Отмена"; +"Settings" = "Настройки"; +"Confirm" = "Подтвердить"; + +"Location is currently disabled" = "Местоположение в данный момент недоступно."; +"Permission for Location was denied" = "Доступ к местоположению был запрещён."; +"Please enable access to Location in the Settings app." = "Пожалуйста, разрешите доступ к местоположению в настройках."; +"%@ would like to access your Location" = "%@ пытается запросить ваше местоположение."; +"Please enable access to Location." = "Пожалуйста, разрешите доступ к местоположению."; + +"Motion is currently disabled" = "Данные движения в данный момент недоступны."; +"Permission for Motion was denied" = "Доступ к данным движения был запрещён."; +"Please enable access to Motion in the Settings app." = "Пожалуйста, разрешите доступ к данным движения в настройках."; +"%@ would like to access your Motion" = "%@ пытается запросить данные движения."; +"Please enable access to Motion." = "Пожалуйста, разрешите доступ к вашим данным движения."; + +"Notifications is currently disabled" = "Уведомления в данный момент недоступны."; +"Permission for Notifications was denied" = "Отправка уведомлений была запрещёна."; +"Please enable access to Notifications in the Settings app." = "Пожалуйста, разрешите доступ к уведомлениям в настройках."; +"%@ would like to access your Notifications" = "%@ хочет отправлять вам уведомления."; +"Please enable access to Notifications." = "Пожалуйста, разрешите отправлять вам уведомления."; + +"Bluetooth is currently disabled" = "Bluetooth в данный момент недоступен."; +"Permission for Bluetooth was denied" = "Доступ к Bluetooth был запрещён."; +"Please enable access to Bluetooth in the Settings app." = "Пожалуйста, разрешите доступ к Bluetooth в настройках."; +"%@ would like to access your Bluetooth" = "%@ хочет использовать Bluetooth."; +"Please enable access to Bluetooth." = "Пожалуйста, разрешите доступ к Bluetooth."; + +"Photos is currently disabled" = "Библиотека фото в данный момент недоступна."; +"Permission for Photos was denied" = "Доступ к библиотеке фото был запрещён."; +"Please enable access to Photos in the Settings app." = "Пожалуйста, разрешите доступ к фото в настройках."; +"%@ would like to access your Photos" = "%@ запрашивает доступ к вашим фото."; +"Please enable access to Photos." = "Пожалуйста, разрешите доступ к вашим фото."; From adfae1da2d62bb33abf56c204c140a8f90e93cd1 Mon Sep 17 00:00:00 2001 From: Yaroslav Erohin Date: Sun, 15 Jan 2017 16:07:31 +0300 Subject: [PATCH 4/5] commented out a wtf check and filled an issue with developer https://github.com/delba/Permission/issues/88 --- Source/PermissionButton.swift | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Source/PermissionButton.swift b/Source/PermissionButton.swift index 66021dc..5488289 100644 --- a/Source/PermissionButton.swift +++ b/Source/PermissionButton.swift @@ -117,8 +117,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified title. */ open func setTitle(_ title: String?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if titles[state] == nil { titles[state] = [:] } @@ -133,8 +133,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specifed titles. */ open func setTitles(_ titles: [PermissionStatus: String?], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if self.titles[state] == nil { self.titles[state] = [:] } @@ -177,8 +177,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified title. */ open func setAttributedTitle(_ title: NSAttributedString?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if attributedTitles[state] == nil { attributedTitles[state] = [:] } @@ -193,8 +193,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified titles. */ open func setAttributedTitles(_ titles: [PermissionStatus: NSAttributedString?], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if attributedTitles[state] == nil { attributedTitles[state] = [:] } @@ -237,8 +237,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified color. */ open func setTitleColor(_ color: UIColor?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if titleColors[state] == nil { titleColors[state] = [:] } @@ -253,8 +253,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified colors. */ open func setTitleColors(_ colors: [PermissionStatus: UIColor?], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if titleColors[state] == nil { titleColors[state] = [:] } @@ -297,8 +297,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified color. */ open func setTitleShadowColor(_ color: UIColor?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if titleShadowColors[state] == nil { titleShadowColors[state] = [:] } @@ -313,8 +313,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified colors. */ open func setTitleShadowColors(_ colors: [PermissionStatus: UIColor?], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if titleShadowColors[state] == nil { titleShadowColors[state] = [:] } @@ -357,8 +357,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified image. */ open func setImage(_ image: UIImage?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if images[state] == nil { images[state] = [:] } @@ -373,8 +373,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified images. */ open func setImages(_ images: [PermissionStatus: UIImage], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if self.images[state] == nil { self.images[state] = [:] } @@ -417,8 +417,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified image. */ open func setBackgroundImage(_ image: UIImage?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if backgroundImages[state] == nil { backgroundImages[state] = [:] } @@ -433,8 +433,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified images. */ open func setBackgroundImages(_ images: [PermissionStatus: UIImage], forState state: UIControlState = UIControlState()) { - guard [.highlighted].contains(state) else { return } - +// guard [.highlighted].contains(state) else { return } + if backgroundImages[state] == nil { backgroundImages[state] = [:] } From 611800564843a1e1d329b8ae3b516ad8d21e32b2 Mon Sep 17 00:00:00 2001 From: Yaroslav Erohin Date: Mon, 6 Mar 2017 01:08:08 +0300 Subject: [PATCH 5/5] Revert "commented out a wtf check" This reverts commit adfae1da2d62bb33abf56c204c140a8f90e93cd1. --- Source/PermissionButton.swift | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Source/PermissionButton.swift b/Source/PermissionButton.swift index 5488289..66021dc 100644 --- a/Source/PermissionButton.swift +++ b/Source/PermissionButton.swift @@ -117,8 +117,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified title. */ open func setTitle(_ title: String?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if titles[state] == nil { titles[state] = [:] } @@ -133,8 +133,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specifed titles. */ open func setTitles(_ titles: [PermissionStatus: String?], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if self.titles[state] == nil { self.titles[state] = [:] } @@ -177,8 +177,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified title. */ open func setAttributedTitle(_ title: NSAttributedString?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if attributedTitles[state] == nil { attributedTitles[state] = [:] } @@ -193,8 +193,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified titles. */ open func setAttributedTitles(_ titles: [PermissionStatus: NSAttributedString?], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if attributedTitles[state] == nil { attributedTitles[state] = [:] } @@ -237,8 +237,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified color. */ open func setTitleColor(_ color: UIColor?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if titleColors[state] == nil { titleColors[state] = [:] } @@ -253,8 +253,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified colors. */ open func setTitleColors(_ colors: [PermissionStatus: UIColor?], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if titleColors[state] == nil { titleColors[state] = [:] } @@ -297,8 +297,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified color. */ open func setTitleShadowColor(_ color: UIColor?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if titleShadowColors[state] == nil { titleShadowColors[state] = [:] } @@ -313,8 +313,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified colors. */ open func setTitleShadowColors(_ colors: [PermissionStatus: UIColor?], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if titleShadowColors[state] == nil { titleShadowColors[state] = [:] } @@ -357,8 +357,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified image. */ open func setImage(_ image: UIImage?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if images[state] == nil { images[state] = [:] } @@ -373,8 +373,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified images. */ open func setImages(_ images: [PermissionStatus: UIImage], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if self.images[state] == nil { self.images[state] = [:] } @@ -417,8 +417,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified image. */ open func setBackgroundImage(_ image: UIImage?, forStatus status: PermissionStatus, andState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if backgroundImages[state] == nil { backgroundImages[state] = [:] } @@ -433,8 +433,8 @@ open class PermissionButton: UIButton { - parameter state: The state that uses the specified images. */ open func setBackgroundImages(_ images: [PermissionStatus: UIImage], forState state: UIControlState = UIControlState()) { -// guard [.highlighted].contains(state) else { return } - + guard [.highlighted].contains(state) else { return } + if backgroundImages[state] == nil { backgroundImages[state] = [:] }