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

Added Swift 4.2 support #74

Open
wants to merge 2 commits into
base: new
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions Alerts&Pickers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ Download and drop `/Source` folder in your project.

## Requirements

* Swift 4
* Swift 4.2
* iOS 11 or higher

## Authors
Expand Down
6 changes: 3 additions & 3 deletions Source/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension String {
subscript (r: Range<Int>) -> 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 {
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions Source/Extensions/UIAlertController+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
20 changes: 10 additions & 10 deletions Source/Extensions/UIImageView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Source/Extensions/UISegmentedControl+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Extensions/UITextField+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ 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
imageView.image = imageView.image?.withRenderingMode(.alwaysTemplate)
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
imageView.image = imageView.image?.withRenderingMode(.alwaysTemplate)
imageView.tintColor = color
rightView = imageView
} else {
rightViewMode = UITextFieldViewMode.never
rightViewMode = UITextField.ViewMode.never
rightView = nil
}
}
Expand All @@ -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])
}
}
6 changes: 3 additions & 3 deletions Source/Pickers/Contacts/ContactsPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Pickers/Contacts/Views/ContactCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Source/Pickers/Date/DatePickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Source/Pickers/Image/ImagePickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading