From 0fa30595ec1201030df0a38f9f2fdcf5f41bc073 Mon Sep 17 00:00:00 2001 From: Alireza Toghyiani Date: Wed, 30 Sep 2020 11:13:13 +0330 Subject: [PATCH] fix date picker bug forr iOS 14 --- Alerts&Pickers.xcodeproj/project.pbxproj | 4 +-- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ Source/Extensions/String+Extensions.swift | 2 +- .../UISegmentedControl+Extensions.swift | 6 ++-- .../Date/DatePickerViewController.swift | 34 ++++++++++++++++++- .../Managers/SearchHistoryManager.swift | 4 +-- .../PhotoLibraryPickerViewController.swift | 2 ++ .../TelegramPickerViewController.swift | 3 ++ 8 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 Alerts&Pickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Alerts&Pickers.xcodeproj/project.pbxproj b/Alerts&Pickers.xcodeproj/project.pbxproj index 770321c2..2e748a0c 100644 --- a/Alerts&Pickers.xcodeproj/project.pbxproj +++ b/Alerts&Pickers.xcodeproj/project.pbxproj @@ -749,7 +749,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XL743FKK28; + DEVELOPMENT_TEAM = AJLMAG95WU; INFOPLIST_FILE = "$(SRCROOT)/Example/Resources/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "AA.Alerts-Pickers"; @@ -764,7 +764,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XL743FKK28; + DEVELOPMENT_TEAM = AJLMAG95WU; INFOPLIST_FILE = "$(SRCROOT)/Example/Resources/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "AA.Alerts-Pickers"; diff --git a/Alerts&Pickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Alerts&Pickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Alerts&Pickers.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Source/Extensions/String+Extensions.swift b/Source/Extensions/String+Extensions.swift index e982124d..3878d2d4 100644 --- a/Source/Extensions/String+Extensions.swift +++ b/Source/Extensions/String+Extensions.swift @@ -13,7 +13,7 @@ extension String { subscript (r: Range) -> String { let start = index(startIndex, offsetBy: r.lowerBound) let end = index(startIndex, offsetBy: r.upperBound) - return String(self[Range(start ..< end)]) + return String(self[start ..< end]) } var containsAlphabets: Bool { diff --git a/Source/Extensions/UISegmentedControl+Extensions.swift b/Source/Extensions/UISegmentedControl+Extensions.swift index 9775cb4e..1f49eb71 100644 --- a/Source/Extensions/UISegmentedControl+Extensions.swift +++ b/Source/Extensions/UISegmentedControl+Extensions.swift @@ -3,7 +3,7 @@ import UIKit public extension UISegmentedControl { /// Font of titles - public func title(font: UIFont) { + func title(font: UIFont) { let attributes: [NSAttributedStringKey: Any] = [.font: font] setTitleTextAttributes(attributes, for: UIControlState()) //setNeedsDisplay() @@ -11,7 +11,7 @@ public extension UISegmentedControl { } /// Segments titles. - public var segmentTitles: [String?] { + var segmentTitles: [String?] { get { var titles: [String?] = [] var i = 0 @@ -30,7 +30,7 @@ public extension UISegmentedControl { } /// Segments images. - public var segmentImages: [UIImage?] { + var segmentImages: [UIImage?] { get { var images: [UIImage?] = [] var i = 0 diff --git a/Source/Pickers/Date/DatePickerViewController.swift b/Source/Pickers/Date/DatePickerViewController.swift index ac6bf256..41ed459c 100644 --- a/Source/Pickers/Date/DatePickerViewController.swift +++ b/Source/Pickers/Date/DatePickerViewController.swift @@ -10,11 +10,30 @@ extension UIAlertController { /// - minimumDate: minimum date of date picker /// - maximumDate: maximum date of date picker /// - action: an action for datePicker value change + @available(iOS 13.4, *) + func addDatePicker(mode: UIDatePickerMode, date: Date?, minimumDate: Date? = nil, maximumDate: Date? = nil, style: UIDatePickerStyle = .wheels, action: DatePickerViewController.Action?) { + let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate,style: style ,action: action) + + set(vc: datePicker, height: 217) + } + + /// Add a date picker + /// + /// - Parameters: + /// - mode: date picker mode + /// - date: selected date of date picker + /// - minimumDate: minimum date of date picker + /// - maximumDate: maximum date of date picker + /// - action: an action for datePicker value change + /// func addDatePicker(mode: UIDatePickerMode, date: Date?, minimumDate: Date? = nil, maximumDate: Date? = nil, action: DatePickerViewController.Action?) { - let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate, action: action) + let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate ,action: action) + set(vc: datePicker, height: 217) } + + } final class DatePickerViewController: UIViewController { @@ -28,6 +47,19 @@ final class DatePickerViewController: UIViewController { return $0 }(UIDatePicker()) + + @available(iOS 13.4, *) + required init(mode: UIDatePickerMode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil,style: UIDatePickerStyle, action: Action?) { + super.init(nibName: nil, bundle: nil) + datePicker.datePickerMode = mode + datePicker.date = date ?? Date() + datePicker.minimumDate = minimumDate + datePicker.maximumDate = maximumDate + datePicker.preferredDatePickerStyle = style + self.action = action + } + + required init(mode: UIDatePickerMode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) { super.init(nibName: nil, bundle: nil) datePicker.datePickerMode = mode diff --git a/Source/Pickers/Location/Managers/SearchHistoryManager.swift b/Source/Pickers/Location/Managers/SearchHistoryManager.swift index 4853926e..b71e3fed 100755 --- a/Source/Pickers/Location/Managers/SearchHistoryManager.swift +++ b/Source/Pickers/Location/Managers/SearchHistoryManager.swift @@ -9,14 +9,14 @@ struct SearchHistoryManager { func history() -> [Location] { let history = defaults.object(forKey: HistoryKey) as? [NSDictionary] ?? [] - return history.flatMap(Location.fromDefaultsDic) + return history.compactMap(Location.fromDefaultsDic) } func addToHistory(_ location: Location) { guard let dic = location.toDefaultsDic() else { return } var history = defaults.object(forKey: HistoryKey) as? [NSDictionary] ?? [] - let historyNames = history.flatMap { $0[LocationDicKeys.name] as? String } + let historyNames = history.compactMap { $0[LocationDicKeys.name] as? String } let alreadyInHistory = location.name.flatMap(historyNames.contains) ?? false if !alreadyInHistory { history.insert(dic, at: 0) diff --git a/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift b/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift index 05bc9eb6..e8109ff4 100644 --- a/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift +++ b/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift @@ -188,6 +188,8 @@ final class PhotoLibraryPickerViewController: UIViewController { self.alertController?.dismiss(animated: true) } alert.show() + case .limited: + break } } diff --git a/Source/Pickers/Telegram/TelegramPickerViewController.swift b/Source/Pickers/Telegram/TelegramPickerViewController.swift index e568a651..2ed4fbcc 100644 --- a/Source/Pickers/Telegram/TelegramPickerViewController.swift +++ b/Source/Pickers/Telegram/TelegramPickerViewController.swift @@ -220,7 +220,10 @@ final class TelegramPickerViewController: UIViewController { self.alertController?.dismiss(animated: true) } alert.show() + case .limited: + break } + } func fetchPhotos(completionHandler: @escaping ([PHAsset]) -> ()) {