Skip to content

Commit

Permalink
Support xocde 10 with swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
vanthanhtran245 committed Sep 28, 2018
1 parent 593f844 commit bfe6ef2
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions AlertAndPickerUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.sunflower.AlertAndPickerUtils;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -739,7 +739,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.sunflower.AlertAndPickerUtils;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 3 additions & 3 deletions AlertAndPickerUtils/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public 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[start..<end])
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public 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)
public convenience init(style: UIAlertControllerStyle, source: UIView? = nil, title: String? = nil, message: String? = nil, tintColor: UIColor? = nil) {
public 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 @@ public 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 @@ public 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)
public func addAction(image: UIImage? = nil, title: String, color: UIColor? = nil, style: UIAlertActionStyle = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) {
public 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 @@ public extension UIAlertController {

public 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 @@ public extension UIAlertController {

public 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 AlertAndPickerUtils/Extensions/UIImageView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public 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.
public func setImage(string: String?, color: UIColor? = nil, circular: Bool = false, textAttributes: [NSAttributedStringKey: Any]? = nil) {
public 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 @@ public 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 @@ public 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

public 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 @@ public 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
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 AlertAndPickerUtils/Extensions/UITextField+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ public 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])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public class ContactsPickerViewController: 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 contacts.")
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public 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 @@ public class DatePickerViewController: UIViewController {
return $0
}(UIDatePicker())

required public init(mode: UIDatePickerMode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) {
required public init(mode: UIDatePicker.Mode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) {
super.init(nibName: nil, bundle: Bundle.alertAndPicker)
datePicker.datePickerMode = mode
datePicker.date = date ?? Date()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public 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 @@ public 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.bounces = false
$0.backgroundColor = .clear
$0.maskToBounds = false
Expand All @@ -89,7 +89,7 @@ public class ImagePickerViewController: UIViewController {

// MARK: Initialize

required public init(flow: UICollectionViewScrollDirection, paging: Bool, images: [UIImage], selection: SelectionType?) {
required public init(flow: UICollectionView.ScrollDirection, paging: Bool, images: [UIImage], selection: SelectionType?) {
super.init(nibName: nil, bundle: Bundle.alertAndPicker)
self.images = images
self.selection = selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class LocalePickerViewController: UIViewController {
fileprivate lazy var indicatorView: UIActivityIndicatorView = {
$0.color = .lightGray
return $0
}(UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge))
}(UIActivityIndicatorView(style: .whiteLarge))

// MARK: Initialize

Expand Down
2 changes: 1 addition & 1 deletion AlertAndPickerUtils/Pickers/Locale/Views/CountryCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public 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
Expand Down
Loading

0 comments on commit bfe6ef2

Please sign in to comment.