From f9b8f6868d3a97ce0b163d6a46e9c338294c9fa7 Mon Sep 17 00:00:00 2001 From: Federico Gentile Date: Thu, 17 Jan 2019 18:45:53 +0100 Subject: [PATCH 1/2] Added Swift 4.2 support --- Alerts&Pickers.xcodeproj/project.pbxproj | 8 ++++---- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Example/AppDelegate.swift | 2 +- Example/ViewController.swift | 4 ++-- Source/Extensions/String+Extensions.swift | 6 +++--- .../UIAlertController+Extensions.swift | 10 +++++----- .../Extensions/UIImageView+Extensions.swift | 20 +++++++++---------- .../UISegmentedControl+Extensions.swift | 4 ++-- .../Extensions/UITextField+Extensions.swift | 12 +++++------ .../ContactsPickerViewController.swift | 6 +++--- .../Pickers/Contacts/Views/ContactCell.swift | 2 +- .../Date/DatePickerViewController.swift | 4 ++-- .../Image/ImagePickerViewController.swift | 6 +++--- .../Locale/LocalePickerViewController.swift | 5 ++--- Source/Pickers/Locale/Views/CountryCell.swift | 2 +- .../Pickers/Locale/Views/CurrencyCell.swift | 2 +- .../Pickers/Locale/Views/PhoneCodeCell.swift | 2 +- .../LocationPickerViewController.swift | 13 ++++++------ .../PhotoLibraryPickerViewController.swift | 8 ++++---- .../TelegramPickerViewController.swift | 4 ++-- .../Telegram/Views/LikeButtonCell.swift | 3 +-- .../Viewers/Models/AttributedTextBlock.swift | 8 ++++---- Source/Viewers/TextViewController.swift | 2 +- Source/Views/GradientSlider.swift | 7 +++---- Source/Views/Label.swift | 2 +- 25 files changed, 78 insertions(+), 72 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..2e8ef62d 100644 --- a/Alerts&Pickers.xcodeproj/project.pbxproj +++ b/Alerts&Pickers.xcodeproj/project.pbxproj @@ -749,12 +749,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XL743FKK28; + DEVELOPMENT_TEAM = H8UVDSE8R7; INFOPLIST_FILE = "$(SRCROOT)/Example/Resources/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "AA.Alerts-Pickers"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -764,12 +764,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = XL743FKK28; + DEVELOPMENT_TEAM = H8UVDSE8R7; INFOPLIST_FILE = "$(SRCROOT)/Example/Resources/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "AA.Alerts-Pickers"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; 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/Example/AppDelegate.swift b/Example/AppDelegate.swift index e1a46626..4c5c9e78 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -5,7 +5,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = UINavigationController(rootViewController: ViewController()) window?.makeKeyAndVisible() diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 09376c63..df8ddb0a 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -99,7 +99,7 @@ class ViewController: UIViewController { // MARK: Properties - fileprivate var alertStyle: UIAlertControllerStyle = .actionSheet + fileprivate var alertStyle: UIAlertController.Style = .actionSheet fileprivate lazy var segments: SegmentedControl = { let styles: [String] = ["Alert", "ActionSheet"] @@ -120,7 +120,7 @@ class ViewController: UIViewController { $0.register(TypeOneCell.self, forCellWithReuseIdentifier: TypeOneCell.identifier) $0.showsVerticalScrollIndicator = false $0.showsHorizontalScrollIndicator = false - $0.decelerationRate = UIScrollViewDecelerationRateFast + $0.decelerationRate = UIScrollView.DecelerationRate.fast //$0.contentInsetAdjustmentBehavior = .never $0.bounces = true $0.backgroundColor = .white diff --git a/Source/Extensions/String+Extensions.swift b/Source/Extensions/String+Extensions.swift index e982124d..5c980d5c 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[Range(start.hashValue ..< end.hashValue)]) } var containsAlphabets: Bool { @@ -41,12 +41,12 @@ public extension String { /// Underlined string public var underline: NSAttributedString { - return NSAttributedString(string: self, attributes: [.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) + return NSAttributedString(string: self, attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue]) } /// Strikethrough string. public var strikethrough: NSAttributedString { - return NSAttributedString(string: self, attributes: [.strikethroughStyle: NSNumber(value: NSUnderlineStyle.styleSingle.rawValue as Int)]) + return NSAttributedString(string: self, attributes: [.strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue as Int)]) } /// Italic string. diff --git a/Source/Extensions/UIAlertController+Extensions.swift b/Source/Extensions/UIAlertController+Extensions.swift index 8ca0f37c..ad599943 100644 --- a/Source/Extensions/UIAlertController+Extensions.swift +++ b/Source/Extensions/UIAlertController+Extensions.swift @@ -12,7 +12,7 @@ extension UIAlertController { /// - message: alert controller's message (default is nil). /// - defaultActionButtonTitle: default action button title (default is "OK") /// - tintColor: alert controller's tint color (default is nil) - convenience init(style: UIAlertControllerStyle, source: UIView? = nil, title: String? = nil, message: String? = nil, tintColor: UIColor? = nil) { + convenience init(style: UIAlertController.Style, source: UIView? = nil, title: String? = nil, message: String? = nil, tintColor: UIColor? = nil) { self.init(title: title, message: message, preferredStyle: style) // TODO: for iPad or other views @@ -48,7 +48,7 @@ extension UIAlertController { /// - animated: set true to animate presentation of alert controller (default is true). /// - vibrate: set true to vibrate the device while presenting the alert (default is false). /// - completion: an optional completion handler to be called after presenting alert controller (default is nil). - public func show(animated: Bool = true, vibrate: Bool = false, style: UIBlurEffectStyle? = nil, completion: (() -> Void)? = nil) { + public func show(animated: Bool = true, vibrate: Bool = false, style: UIBlurEffect.Style? = nil, completion: (() -> Void)? = nil) { /// TODO: change UIBlurEffectStyle if let style = style { @@ -72,7 +72,7 @@ extension UIAlertController { /// - style: action style (default is UIAlertActionStyle.default) /// - isEnabled: isEnabled status for action (default is true) /// - handler: optional action handler to be called when button is tapped (default is nil) - func addAction(image: UIImage? = nil, title: String, color: UIColor? = nil, style: UIAlertActionStyle = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) { + func addAction(image: UIImage? = nil, title: String, color: UIColor? = nil, style: UIAlertAction.Style = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) { //let isPad: Bool = UIDevice.current.userInterfaceIdiom == .pad //let action = UIAlertAction(title: title, style: isPad && style == .cancel ? .default : style, handler: handler) let action = UIAlertAction(title: title, style: style, handler: handler) @@ -106,7 +106,7 @@ extension UIAlertController { func setTitle(font: UIFont, color: UIColor) { guard let title = self.title else { return } - let attributes: [NSAttributedStringKey: Any] = [.font: font, .foregroundColor: color] + let attributes: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: color] let attributedTitle = NSMutableAttributedString(string: title, attributes: attributes) setValue(attributedTitle, forKey: "attributedTitle") } @@ -126,7 +126,7 @@ extension UIAlertController { func setMessage(font: UIFont, color: UIColor) { guard let message = self.message else { return } - let attributes: [NSAttributedStringKey: Any] = [.font: font, .foregroundColor: color] + let attributes: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: color] let attributedMessage = NSMutableAttributedString(string: message, attributes: attributes) setValue(attributedMessage, forKey: "attributedMessage") } diff --git a/Source/Extensions/UIImageView+Extensions.swift b/Source/Extensions/UIImageView+Extensions.swift index 3a44b706..5123efbe 100644 --- a/Source/Extensions/UIImageView+Extensions.swift +++ b/Source/Extensions/UIImageView+Extensions.swift @@ -9,7 +9,7 @@ extension UIImageView { /// - color: This optional paramter sets the background of the image. By default, a random color will be generated. /// - circular: This boolean will determine if the image view will be clipped to a circular shape. /// - textAttributes: This dictionary allows you to specify font, text color, shadow properties, etc. - open func setImage(string: String?, color: UIColor? = nil, circular: Bool = false, textAttributes: [NSAttributedStringKey: Any]? = nil) { + open func setImage(string: String?, color: UIColor? = nil, circular: Bool = false, textAttributes: [NSAttributedString.Key: Any]? = nil) { let image = imageSnap(text: string != nil ? string?.initials : "", color: color ?? UIColor.random, circular: circular, textAttributes: textAttributes) @@ -18,7 +18,7 @@ extension UIImageView { } } - private func imageSnap(text: String?, color: UIColor, circular: Bool, textAttributes: [NSAttributedStringKey: Any]?) -> UIImage? { + private func imageSnap(text: String?, color: UIColor, circular: Bool, textAttributes: [NSAttributedString.Key: Any]?) -> UIImage? { let scale = Float(UIScreen.main.scale) var size = bounds.size @@ -41,7 +41,7 @@ extension UIImageView { // Text if let text = text { - let attributes: [NSAttributedStringKey: Any] = textAttributes ?? [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 15.0)] + let attributes: [NSAttributedString.Key: Any] = textAttributes ?? [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 15.0)] let textSize = text.size(withAttributes: attributes) let bounds = self.bounds @@ -91,24 +91,24 @@ let kGradientBotomOffset: HSVOffset = (hue: 0.025, saturation: -0.05, brightness extension UIImageView { - public func setImageForName(string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?, gradient: Bool = false) { + public func setImageForName(string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedString.Key: AnyObject]?, gradient: Bool = false) { setImageForName(string: string, backgroundColor: backgroundColor, circular: circular, textAttributes: textAttributes, gradient: gradient, gradientColors: nil) } - public func setImageForName(string: String, gradientColors: GradientColors? = nil, circular: Bool = true, textAttributes: [NSAttributedStringKey: AnyObject]? = nil) { + public func setImageForName(string: String, gradientColors: GradientColors? = nil, circular: Bool = true, textAttributes: [NSAttributedString.Key: AnyObject]? = nil) { setImageForName(string: string, backgroundColor: nil, circular: circular, textAttributes: textAttributes, gradient: true, gradientColors: gradientColors) } - public func setImageForName(string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]? = nil, gradient: Bool = false, gradientColors: GradientColors? = nil) { + public func setImageForName(string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedString.Key: AnyObject]? = nil, gradient: Bool = false, gradientColors: GradientColors? = nil) { let initials: String = initialsFromString(string: string) let color: UIColor = (backgroundColor != nil) ? backgroundColor! : randomColor(for: string) let gradientColors = gradientColors ?? topAndBottomColors(for: color) - let attributes: [NSAttributedStringKey: AnyObject] = (textAttributes != nil) ? textAttributes! : [ - NSAttributedStringKey.font: self.fontForFontName(name: nil), - NSAttributedStringKey.foregroundColor: UIColor.white + let attributes: [NSAttributedString.Key: AnyObject] = (textAttributes != nil) ? textAttributes! : [ + NSAttributedString.Key.font: self.fontForFontName(name: nil), + NSAttributedString.Key.foregroundColor: UIColor.white ] self.image = imageSnapshot(text: initials, backgroundColor: color, circular: circular, textAttributes: attributes, gradient: gradient, gradientColors: gradientColors) @@ -126,7 +126,7 @@ extension UIImageView { } - private func imageSnapshot(text imageText: String, backgroundColor: UIColor, circular: Bool, textAttributes: [NSAttributedStringKey : AnyObject], gradient: Bool, gradientColors: GradientColors) -> UIImage { + private func imageSnapshot(text imageText: String, backgroundColor: UIColor, circular: Bool, textAttributes: [NSAttributedString.Key : AnyObject], gradient: Bool, gradientColors: GradientColors) -> UIImage { let scale: CGFloat = UIScreen.main.scale diff --git a/Source/Extensions/UISegmentedControl+Extensions.swift b/Source/Extensions/UISegmentedControl+Extensions.swift index 9775cb4e..ea7fac49 100644 --- a/Source/Extensions/UISegmentedControl+Extensions.swift +++ b/Source/Extensions/UISegmentedControl+Extensions.swift @@ -4,8 +4,8 @@ public extension UISegmentedControl { /// Font of titles public func title(font: UIFont) { - let attributes: [NSAttributedStringKey: Any] = [.font: font] - setTitleTextAttributes(attributes, for: UIControlState()) + let attributes: [NSAttributedString.Key: Any] = [.font: font] + setTitleTextAttributes(attributes, for: UIControl.State()) //setNeedsDisplay() //layoutIfNeeded() } diff --git a/Source/Extensions/UITextField+Extensions.swift b/Source/Extensions/UITextField+Extensions.swift index c72de82a..314010d2 100644 --- a/Source/Extensions/UITextField+Extensions.swift +++ b/Source/Extensions/UITextField+Extensions.swift @@ -12,7 +12,7 @@ extension UITextField { func left(image: UIImage?, color: UIColor = .black) { if let image = image { - leftViewMode = UITextFieldViewMode.always + leftViewMode = UITextField.ViewMode.always let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) imageView.contentMode = .scaleAspectFit imageView.image = image @@ -20,14 +20,14 @@ extension UITextField { imageView.tintColor = color leftView = imageView } else { - leftViewMode = UITextFieldViewMode.never + leftViewMode = UITextField.ViewMode.never leftView = nil } } func right(image: UIImage?, color: UIColor = .black) { if let image = image { - rightViewMode = UITextFieldViewMode.always + rightViewMode = UITextField.ViewMode.always let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) imageView.contentMode = .scaleAspectFit imageView.image = image @@ -35,7 +35,7 @@ extension UITextField { imageView.tintColor = color rightView = imageView } else { - rightViewMode = UITextFieldViewMode.never + rightViewMode = UITextField.ViewMode.never rightView = nil } } @@ -49,11 +49,11 @@ public extension UITextField { /// /// - Parameter color: placeholder text color. public func setPlaceHolderTextColor(_ color: UIColor) { - self.attributedPlaceholder = NSAttributedString(string:self.placeholder != nil ? self.placeholder! : "", attributes:[NSAttributedStringKey.foregroundColor: color]) + self.attributedPlaceholder = NSAttributedString(string:self.placeholder != nil ? self.placeholder! : "", attributes:[NSAttributedString.Key.foregroundColor: color]) } /// Set placeholder text and its color func placeholder(text value: String, color: UIColor = .red) { - self.attributedPlaceholder = NSAttributedString(string: value, attributes: [ NSAttributedStringKey.foregroundColor : color]) + self.attributedPlaceholder = NSAttributedString(string: value, attributes: [ NSAttributedString.Key.foregroundColor : color]) } } diff --git a/Source/Pickers/Contacts/ContactsPickerViewController.swift b/Source/Pickers/Contacts/ContactsPickerViewController.swift index af25d4db..34d36cca 100644 --- a/Source/Pickers/Contacts/ContactsPickerViewController.swift +++ b/Source/Pickers/Contacts/ContactsPickerViewController.swift @@ -167,9 +167,9 @@ final class ContactsPickerViewController: UIViewController { case .denied, .restricted: /// User has denied the current app to access the contacts. let productName = Bundle.main.infoDictionary!["CFBundleName"]! - let alert = UIAlertController(style: .alert, title: "Permission denied", message: "\(productName) does not have access to contacts. Please, allow the application to access to your contacts.") + let alert = UIAlertController(title: "Permission denied", message: "\(productName) does not have access to contacts. Please, allow the application to access to your contacts.", preferredStyle: .alert) alert.addAction(title: "Settings", style: .destructive) { action in - if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) { + if let settingsURL = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(settingsURL) } } @@ -189,7 +189,7 @@ final class ContactsPickerViewController: UIViewController { case .error(let error): Log("------ error") - let alert = UIAlertController(style: .alert, title: "Error", message: error.localizedDescription) + let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert) alert.addAction(title: "OK") { [unowned self] action in self.alertController?.dismiss(animated: true) } diff --git a/Source/Pickers/Contacts/Views/ContactCell.swift b/Source/Pickers/Contacts/Views/ContactCell.swift index a4297ab0..c9bd703b 100644 --- a/Source/Pickers/Contacts/Views/ContactCell.swift +++ b/Source/Pickers/Contacts/Views/ContactCell.swift @@ -11,7 +11,7 @@ final class ContactTableViewCell: UITableViewCell { // MARK: Initialize - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = nil diff --git a/Source/Pickers/Date/DatePickerViewController.swift b/Source/Pickers/Date/DatePickerViewController.swift index ac6bf256..91bba9b5 100644 --- a/Source/Pickers/Date/DatePickerViewController.swift +++ b/Source/Pickers/Date/DatePickerViewController.swift @@ -11,7 +11,7 @@ extension UIAlertController { /// - 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?) { + func addDatePicker(mode: UIDatePicker.Mode, date: Date?, minimumDate: Date? = nil, maximumDate: Date? = nil, action: DatePickerViewController.Action?) { let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate, action: action) set(vc: datePicker, height: 217) } @@ -28,7 +28,7 @@ final class DatePickerViewController: UIViewController { return $0 }(UIDatePicker()) - required init(mode: UIDatePickerMode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) { + required init(mode: UIDatePicker.Mode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) { super.init(nibName: nil, bundle: nil) datePicker.datePickerMode = mode datePicker.date = date ?? Date() diff --git a/Source/Pickers/Image/ImagePickerViewController.swift b/Source/Pickers/Image/ImagePickerViewController.swift index 764e8811..1cd7bf6b 100644 --- a/Source/Pickers/Image/ImagePickerViewController.swift +++ b/Source/Pickers/Image/ImagePickerViewController.swift @@ -10,7 +10,7 @@ extension UIAlertController { /// - images: for content to select /// - selection: type and action for selection of image/images - func addImagePicker(flow: UICollectionViewScrollDirection, paging: Bool, images: [UIImage], selection: ImagePickerViewController.SelectionType? = nil) { + func addImagePicker(flow: UICollectionView.ScrollDirection, paging: Bool, images: [UIImage], selection: ImagePickerViewController.SelectionType? = nil) { let vc = ImagePickerViewController(flow: flow, paging: paging, images: images, selection: selection) if UIDevice.current.userInterfaceIdiom == .pad { @@ -68,7 +68,7 @@ final class ImagePickerViewController: UIViewController { $0.register(ItemWithImage.self, forCellWithReuseIdentifier: ItemWithImage.identifier) $0.showsVerticalScrollIndicator = false $0.showsHorizontalScrollIndicator = false - $0.decelerationRate = UIScrollViewDecelerationRateFast + $0.decelerationRate = UIScrollView.DecelerationRate.fast $0.contentInsetAdjustmentBehavior = .never $0.bounces = false $0.backgroundColor = .clear @@ -90,7 +90,7 @@ final class ImagePickerViewController: UIViewController { // MARK: Initialize - required init(flow: UICollectionViewScrollDirection, paging: Bool, images: [UIImage], selection: SelectionType?) { + required init(flow: UICollectionView.ScrollDirection, paging: Bool, images: [UIImage], selection: SelectionType?) { super.init(nibName: nil, bundle: nil) self.images = images self.selection = selection diff --git a/Source/Pickers/Locale/LocalePickerViewController.swift b/Source/Pickers/Locale/LocalePickerViewController.swift index a0091190..4d152602 100644 --- a/Source/Pickers/Locale/LocalePickerViewController.swift +++ b/Source/Pickers/Locale/LocalePickerViewController.swift @@ -84,7 +84,7 @@ final class LocalePickerViewController: UIViewController { fileprivate lazy var indicatorView: UIActivityIndicatorView = { $0.color = .lightGray return $0 - }(UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)) + }(UIActivityIndicatorView(style: .whiteLarge)) // MARK: Initialize @@ -175,8 +175,7 @@ final class LocalePickerViewController: UIViewController { case .error(let error): DispatchQueue.main.async { - - let alert = UIAlertController(style: .alert, title: error.title, message: error.message) + let alert = UIAlertController(title: error.title, message: error.message, preferredStyle: .alert) alert.addAction(title: "OK", style: .cancel) { action in self.indicatorView.stopAnimating() self.alertController?.dismiss(animated: true) diff --git a/Source/Pickers/Locale/Views/CountryCell.swift b/Source/Pickers/Locale/Views/CountryCell.swift index dc04c673..4556f368 100644 --- a/Source/Pickers/Locale/Views/CountryCell.swift +++ b/Source/Pickers/Locale/Views/CountryCell.swift @@ -9,7 +9,7 @@ final class CountryTableViewCell: UITableViewCell { // MARK: Initialize - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .default, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = nil diff --git a/Source/Pickers/Locale/Views/CurrencyCell.swift b/Source/Pickers/Locale/Views/CurrencyCell.swift index b0ad0336..c377261a 100644 --- a/Source/Pickers/Locale/Views/CurrencyCell.swift +++ b/Source/Pickers/Locale/Views/CurrencyCell.swift @@ -4,7 +4,7 @@ final class CurrencyTableViewCell: UITableViewCell { static let identifier = String(describing: CurrencyTableViewCell.self) - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = nil diff --git a/Source/Pickers/Locale/Views/PhoneCodeCell.swift b/Source/Pickers/Locale/Views/PhoneCodeCell.swift index d2abcec1..1fd4bd28 100644 --- a/Source/Pickers/Locale/Views/PhoneCodeCell.swift +++ b/Source/Pickers/Locale/Views/PhoneCodeCell.swift @@ -4,7 +4,7 @@ final class PhoneCodeTableViewCell: UITableViewCell { static let identifier = String(describing: PhoneCodeTableViewCell.self) - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = nil diff --git a/Source/Pickers/Location/LocationPickerViewController.swift b/Source/Pickers/Location/LocationPickerViewController.swift index 512ac5a4..1cfbab78 100755 --- a/Source/Pickers/Location/LocationPickerViewController.swift +++ b/Source/Pickers/Location/LocationPickerViewController.swift @@ -90,7 +90,7 @@ final class LocationPickerViewController: UIViewController { $0.backgroundColor = UIColor.white.withAlphaComponent(0.8) $0.maskToBounds = true $0.cornerRadius = 22 - $0.setImage(#imageLiteral(resourceName: "geolocation"), for: UIControlState()) + $0.setImage(#imageLiteral(resourceName: "geolocation"), for: UIControl.State()) $0.addTarget(self, action: #selector(LocationPickerViewController.currentLocationPressed), for: .touchUpInside) return $0 @@ -237,7 +237,8 @@ final class LocationPickerViewController: UIViewController { } func showCoordinates(_ coordinate: CLLocationCoordinate2D, animated: Bool = true) { - let region = MKCoordinateRegionMakeWithDistance(coordinate, resultRegionDistance, resultRegionDistance) + + let region = MKCoordinateRegion(center: coordinate, latitudinalMeters: resultRegionDistance, longitudinalMeters: resultRegionDistance) mapView.setRegion(region, animated: animated) } @@ -314,7 +315,7 @@ extension LocationPickerViewController: UISearchResultsUpdating { let term = userInfo[LocationPickerViewController.SearchTermKey] as? String else { return } - let request = MKLocalSearchRequest() + let request = MKLocalSearch.Request() request.naturalLanguageQuery = term if let location = locationManager.location, useCurrentLocationAsHint { @@ -329,7 +330,7 @@ extension LocationPickerViewController: UISearchResultsUpdating { } } - func showItemsForSearchResult(_ searchResult: MKLocalSearchResponse?) { + func showItemsForSearchResult(_ searchResult: MKLocalSearch.Response?) { results.locations = searchResult?.mapItems.map { Location(name: $0.name, placemark: $0.placemark) } ?? [] results.isShowingHistory = false results.tableView.reloadData() @@ -382,13 +383,13 @@ extension LocationPickerViewController: MKMapViewDelegate { func selectLocationButton() -> UIButton { let button = UIButton(frame: CGRect(x: 0, y: 0, width: 70, height: 30)) - button.setTitle(selectButtonTitle, for: UIControlState()) + button.setTitle(selectButtonTitle, for: UIControl.State()) if let titleLabel = button.titleLabel { let width = titleLabel.textRect(forBounds: CGRect(x: 0, y: 0, width: Int.max, height: 30), limitedToNumberOfLines: 1).width button.frame.size = CGSize(width: width + 10, height: 30.0) } button.backgroundColor = UIColor(hex: 0x007AFF) - button.setTitleColor(.white, for: UIControlState()) + button.setTitleColor(.white, for: UIControl.State()) button.borderWidth = 2 button.borderColor = UIColor(hex: 0x007AFF) button.cornerRadius = 5 diff --git a/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift b/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift index 05bc9eb6..53452e55 100644 --- a/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift +++ b/Source/Pickers/PhotoLibrary/PhotoLibraryPickerViewController.swift @@ -12,7 +12,7 @@ extension UIAlertController { /// - images: for content to select /// - selection: type and action for selection of image/images - func addPhotoLibraryPicker(flow: UICollectionViewScrollDirection, paging: Bool, selection: PhotoLibraryPickerViewController.Selection) { + func addPhotoLibraryPicker(flow: UICollectionView.ScrollDirection, paging: Bool, selection: PhotoLibraryPickerViewController.Selection) { let selection: PhotoLibraryPickerViewController.Selection = selection var asset: PHAsset? var assets: [PHAsset] = [] @@ -96,7 +96,7 @@ final class PhotoLibraryPickerViewController: UIViewController { $0.register(ItemWithImage.self, forCellWithReuseIdentifier: String(describing: ItemWithImage.self)) $0.showsVerticalScrollIndicator = false $0.showsHorizontalScrollIndicator = false - $0.decelerationRate = UIScrollViewDecelerationRateFast + $0.decelerationRate = UIScrollView.DecelerationRate.fast $0.contentInsetAdjustmentBehavior = .always $0.bounces = true $0.backgroundColor = .clear @@ -118,7 +118,7 @@ final class PhotoLibraryPickerViewController: UIViewController { // MARK: Initialize - required public init(flow: UICollectionViewScrollDirection, paging: Bool, selection: Selection) { + required public init(flow: UICollectionView.ScrollDirection, paging: Bool, selection: Selection) { super.init(nibName: nil, bundle: nil) self.selection = selection @@ -180,7 +180,7 @@ final class PhotoLibraryPickerViewController: UIViewController { let productName = Bundle.main.infoDictionary!["CFBundleName"]! let alert = UIAlertController(style: .alert, title: "Permission denied", message: "\(productName) does not have access to contacts. Please, allow the application to access to your photo library.") alert.addAction(title: "Settings", style: .destructive) { action in - if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) { + if let settingsURL = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(settingsURL) } } diff --git a/Source/Pickers/Telegram/TelegramPickerViewController.swift b/Source/Pickers/Telegram/TelegramPickerViewController.swift index e568a651..a79a9c68 100644 --- a/Source/Pickers/Telegram/TelegramPickerViewController.swift +++ b/Source/Pickers/Telegram/TelegramPickerViewController.swift @@ -102,7 +102,7 @@ final class TelegramPickerViewController: UIViewController { $0.allowsMultipleSelection = true $0.showsVerticalScrollIndicator = false $0.showsHorizontalScrollIndicator = false - $0.decelerationRate = UIScrollViewDecelerationRateFast + $0.decelerationRate = UIScrollView.DecelerationRate.fast $0.contentInsetAdjustmentBehavior = .never $0.contentInset = UI.insets $0.backgroundColor = .clear @@ -212,7 +212,7 @@ final class TelegramPickerViewController: UIViewController { let productName = Bundle.main.infoDictionary!["CFBundleName"]! let alert = UIAlertController(style: .alert, title: "Permission denied", message: "\(productName) does not have access to contacts. Please, allow the application to access to your photo library.") alert.addAction(title: "Settings", style: .destructive) { action in - if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) { + if let settingsURL = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(settingsURL) } } diff --git a/Source/Pickers/Telegram/Views/LikeButtonCell.swift b/Source/Pickers/Telegram/Views/LikeButtonCell.swift index 3b3786f8..eda06d4a 100644 --- a/Source/Pickers/Telegram/Views/LikeButtonCell.swift +++ b/Source/Pickers/Telegram/Views/LikeButtonCell.swift @@ -8,8 +8,7 @@ final class LikeButtonCell: UITableViewCell { // MARK: Initialize - - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .default, reuseIdentifier: reuseIdentifier) selectionStyle = .none backgroundColor = nil diff --git a/Source/Viewers/Models/AttributedTextBlock.swift b/Source/Viewers/Models/AttributedTextBlock.swift index e6c3c71c..113549e9 100644 --- a/Source/Viewers/Models/AttributedTextBlock.swift +++ b/Source/Viewers/Models/AttributedTextBlock.swift @@ -11,16 +11,16 @@ public enum AttributedTextBlock { let attributedString: NSMutableAttributedString switch self { case .header1(let value): - let attributes: [NSAttributedStringKey: Any] = [.font: UIFont.boldSystemFont(ofSize: 20), .foregroundColor: UIColor.black] + let attributes: [NSAttributedString.Key: Any] = [.font: UIFont.boldSystemFont(ofSize: 20), .foregroundColor: UIColor.black] attributedString = NSMutableAttributedString(string: value, attributes: attributes) case .header2(let value): - let attributes: [NSAttributedStringKey: Any] = [.font: UIFont.boldSystemFont(ofSize: 18), .foregroundColor: UIColor.black] + let attributes: [NSAttributedString.Key: Any] = [.font: UIFont.boldSystemFont(ofSize: 18), .foregroundColor: UIColor.black] attributedString = NSMutableAttributedString(string: value, attributes: attributes) case .normal(let value): - let attributes: [NSAttributedStringKey: Any] = [.font: UIFont.systemFont(ofSize: 15), .foregroundColor: UIColor.black] + let attributes: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 15), .foregroundColor: UIColor.black] attributedString = NSMutableAttributedString(string: value, attributes: attributes) case .list(let value): - let attributes: [NSAttributedStringKey: Any] = [.font: UIFont.systemFont(ofSize: 15), .foregroundColor: UIColor.black] + let attributes: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 15), .foregroundColor: UIColor.black] attributedString = NSMutableAttributedString(string: "∙ " + value, attributes: attributes) } let paragraphStyle = NSMutableParagraphStyle() diff --git a/Source/Viewers/TextViewController.swift b/Source/Viewers/TextViewController.swift index 4e0d45a3..97cf2204 100644 --- a/Source/Viewers/TextViewController.swift +++ b/Source/Viewers/TextViewController.swift @@ -46,7 +46,7 @@ final class TextViewerViewController: UIViewController { case .attributedText(let text): textView.attributedText = text.map { $0.text }.joined(separator: "\n") } - textView.textContainerInset = UIEdgeInsetsMake(UI.hInset, UI.vInset, UI.hInset, UI.vInset) + textView.textContainerInset = UIEdgeInsets(top: UI.hInset, left: UI.vInset, bottom: UI.hInset, right: UI.vInset) //preferredContentSize.height = self.textView.contentSize.height } diff --git a/Source/Views/GradientSlider.swift b/Source/Views/GradientSlider.swift index 96925845..f0b5894c 100755 --- a/Source/Views/GradientSlider.swift +++ b/Source/Views/GradientSlider.swift @@ -276,11 +276,11 @@ import UIKit //MARK: - Layout override open var intrinsicContentSize: CGSize { - return CGSize(width: UIViewNoIntrinsicMetric, height: thumbSize) + return CGSize(width: UIView.noIntrinsicMetric, height: thumbSize) } override open var alignmentRectInsets: UIEdgeInsets { - return UIEdgeInsetsMake(4.0, 2.0, 4.0, 2.0) + return UIEdgeInsets(top: 4.0, left: 2.0, bottom: 4.0, right: 2.0) } override open func layoutSublayers(of layer: CALayer) { @@ -358,8 +358,7 @@ import UIKit set(value: newValue, animated: false) } actionBlock(self,_value) - sendActions(for: [UIControlEvents.valueChanged, UIControlEvents.touchUpInside]) - + sendActions(for: [UIControl.Event.valueChanged, UIControl.Event.touchUpInside]) } //MARK: - Private Functions diff --git a/Source/Views/Label.swift b/Source/Views/Label.swift index c7e9f003..b23b1ecd 100644 --- a/Source/Views/Label.swift +++ b/Source/Views/Label.swift @@ -9,7 +9,7 @@ open class Label: UILabel { open var insets: UIEdgeInsets = .zero override open func drawText(in rect: CGRect) { - super.drawText(in: UIEdgeInsetsInsetRect(rect, insets)) + super.drawText(in: rect.inset(by: insets)) } // Override -intrinsicContentSize: for Auto layout code From e745783f0311322ce4731fd1e4b42b475399167d Mon Sep 17 00:00:00 2001 From: Federico Gentile Date: Thu, 17 Jan 2019 18:52:05 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3057630a..3e2d8169 100755 --- a/README.md +++ b/README.md @@ -454,7 +454,7 @@ Download and drop `/Source` folder in your project. ## Requirements -* Swift 4 +* Swift 4.2 * iOS 11 or higher ## Authors