From e8d266cf0d487598f86385aa2c26372e0a4b1f92 Mon Sep 17 00:00:00 2001 From: Anil Date: Mon, 3 Dec 2018 13:32:52 +0530 Subject: [PATCH] Updated Repository to Swift 4.2 --- Examples/Examples.xcodeproj/project.pbxproj | 10 +++++++--- Examples/Examples/AppDelegate.swift | 2 +- Examples/Examples/ViewControllers/Horizontal.swift | 2 +- Examples/Examples/ViewControllers/ObjectiveC.m | 2 +- Examples/Examples/ViewControllers/StackView.swift | 2 +- .../Examples/ViewControllers/ViewController.swift | 2 +- KSTokenView/KSToken.swift | 2 +- KSTokenView/KSTokenField.swift | 6 +++--- KSTokenView/KSTokenView.swift | 14 +++++++------- KSTokenView/KSUtils.swift | 6 +++--- 10 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index fc727a2..faadea4 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -147,7 +147,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Khawar Shahzad"; TargetAttributes = { C389780A1DFB1FB3009E3D81 = { @@ -244,6 +244,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -251,6 +252,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -300,6 +302,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -307,6 +310,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -349,7 +353,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Examples/Examples-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -365,7 +369,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Examples/Examples-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Examples/Examples/AppDelegate.swift b/Examples/Examples/AppDelegate.swift index c3a5555..ab86644 100644 --- a/Examples/Examples/AppDelegate.swift +++ b/Examples/Examples/AppDelegate.swift @@ -31,7 +31,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 { // Override point for customization after application launch. return true } diff --git a/Examples/Examples/ViewControllers/Horizontal.swift b/Examples/Examples/ViewControllers/Horizontal.swift index bac891d..fd2d1e4 100644 --- a/Examples/Examples/ViewControllers/Horizontal.swift +++ b/Examples/Examples/ViewControllers/Horizontal.swift @@ -29,7 +29,7 @@ class Horizontal: UIViewController { extension Horizontal: KSTokenViewDelegate { func tokenView(_ tokenView: KSTokenView, performSearchWithString string: String, completion: ((_ results: Array) -> Void)?) { - if (string.characters.isEmpty){ + if (string.isEmpty){ completion!(names as Array) return } diff --git a/Examples/Examples/ViewControllers/ObjectiveC.m b/Examples/Examples/ViewControllers/ObjectiveC.m index e0fadfc..81679be 100644 --- a/Examples/Examples/ViewControllers/ObjectiveC.m +++ b/Examples/Examples/ViewControllers/ObjectiveC.m @@ -57,7 +57,7 @@ - (void)didReceiveMemoryWarning { - (void)tokenView:(KSTokenView *)tokenView performSearchWithString:(NSString *)string completion:(void (^)(NSArray *))completion { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSString *requestURL = [NSString stringWithFormat:@"%@%@", requestURLString, string]; + NSString *requestURL = [NSString stringWithFormat:@"%@%@", self->requestURLString, string]; NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:[NSURL URLWithString:requestURL] diff --git a/Examples/Examples/ViewControllers/StackView.swift b/Examples/Examples/ViewControllers/StackView.swift index e7424fb..f87503c 100644 --- a/Examples/Examples/ViewControllers/StackView.swift +++ b/Examples/Examples/ViewControllers/StackView.swift @@ -44,7 +44,7 @@ class StackView: UIViewController { extension StackView: KSTokenViewDelegate { func tokenView(_ tokenView: KSTokenView, performSearchWithString string: String, completion: ((_ results: Array) -> Void)?) { - if (string.characters.isEmpty){ + if (string.isEmpty){ completion!(names as Array) return } diff --git a/Examples/Examples/ViewControllers/ViewController.swift b/Examples/Examples/ViewControllers/ViewController.swift index 27e85ef..c282b68 100644 --- a/Examples/Examples/ViewControllers/ViewController.swift +++ b/Examples/Examples/ViewControllers/ViewController.swift @@ -79,7 +79,7 @@ extension ViewController: UITableViewDataSource { var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentfier) as UITableViewCell? if (cell == nil) { - cell = UITableViewCell(style:UITableViewCellStyle.default, reuseIdentifier:cellIdentfier) + cell = UITableViewCell(style:UITableViewCell.CellStyle.default, reuseIdentifier:cellIdentfier) } cell?.textLabel?.text = examples[indexPath.row] diff --git a/KSTokenView/KSToken.swift b/KSTokenView/KSToken.swift index d04347a..ef4a551 100644 --- a/KSTokenView/KSToken.swift +++ b/KSTokenView/KSToken.swift @@ -162,7 +162,7 @@ open class KSToken : UIControl { let rectangleStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle rectangleStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail rectangleStyle.alignment = NSTextAlignment.center - let rectangleFontAttributes = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: textColor, NSAttributedStringKey.paragraphStyle: rectangleStyle] as [NSAttributedStringKey : Any] + let rectangleFontAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.paragraphStyle: rectangleStyle] as [NSAttributedString.Key : Any] let maxDrawableHeight = max(rect.height , font.lineHeight) let textHeight: CGFloat = KSUtils.getRect(rectangleTextContent as NSString, width: rect.width, height: maxDrawableHeight , font: font).size.height diff --git a/KSTokenView/KSTokenField.swift b/KSTokenView/KSTokenField.swift index 629cef0..f07a5eb 100644 --- a/KSTokenView/KSTokenField.swift +++ b/KSTokenView/KSTokenField.swift @@ -161,7 +161,7 @@ open class KSTokenField: UITextField { text = "" autocorrectionType = UITextAutocorrectionType.no autocapitalizationType = UITextAutocapitalizationType.none - contentVerticalAlignment = UIControlContentVerticalAlignment.top + contentVerticalAlignment = UIControl.ContentVerticalAlignment.top returnKeyType = UIReturnKeyType.done text = KSTextEmpty backgroundColor = UIColor.white @@ -177,7 +177,7 @@ open class KSTokenField: UITextField { _scrollView.delegate = self addSubview(_scrollView) - addTarget(self, action: #selector(KSTokenField.tokenFieldTextDidChange(_:)), for: UIControlEvents.editingChanged) + addTarget(self, action: #selector(KSTokenField.tokenFieldTextDidChange(_:)), for: UIControl.Event.editingChanged) } fileprivate func _setScrollRect() { @@ -252,7 +252,7 @@ open class KSTokenField: UITextField { fileprivate func _insertToken(_ token: KSToken, shouldLayout: Bool = true) { _scrollView.addSubview(token) - _scrollView.bringSubview(toFront: token) + _scrollView.bringSubviewToFront(token) token.setNeedsDisplay() if shouldLayout == true { updateLayout() diff --git a/KSTokenView/KSTokenView.swift b/KSTokenView/KSTokenView.swift index b85a7f2..a7e1442 100644 --- a/KSTokenView/KSTokenView.swift +++ b/KSTokenView/KSTokenView.swift @@ -96,13 +96,13 @@ open class KSTokenView: UIView { //__________________________________________________________________________________ // fileprivate var _tokenField: KSTokenField! - fileprivate var _searchTableView: UITableView = UITableView(frame: .zero, style: UITableViewStyle.plain) + fileprivate var _searchTableView: UITableView = UITableView(frame: .zero, style: UITableView.Style.plain) fileprivate var _resultArray = [AnyObject]() fileprivate var _showingSearchResult = false - fileprivate var _indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray) + fileprivate var _indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray) fileprivate var _searchResultHeight: CGFloat = 200.0 fileprivate var _lastSearchString: String = "" - fileprivate var _intrinsicContentHeight: CGFloat = UIViewNoIntrinsicMetric + fileprivate var _intrinsicContentHeight: CGFloat = UIView.noIntrinsicMetric //MARK: - Public Properties //__________________________________________________________________________________ @@ -419,7 +419,7 @@ open class KSTokenView: UIView { } override open var intrinsicContentSize : CGSize { - return CGSize(width: UIViewNoIntrinsicMetric, height: _intrinsicContentHeight) + return CGSize(width: UIView.noIntrinsicMetric, height: _intrinsicContentHeight) } //MARK: - Public Methods @@ -930,7 +930,7 @@ extension KSTokenView : UITableViewDelegate { } else if (!shouldDisplayAlreadyTokenized) { _resultArray.remove(at: (indexPath as NSIndexPath).row) - tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.left) + tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.left) } } } @@ -954,12 +954,12 @@ extension KSTokenView : UITableViewDataSource { let cellIdentifier = "KSSearchTableCell" cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as UITableViewCell? if (cell == nil) { - cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellIdentifier) + cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: cellIdentifier) } let title = delegate?.tokenView(self, displayTitleForObject: _resultArray[(indexPath as NSIndexPath).row]) cell!.textLabel!.text = (title != nil) ? title : "No Title" - cell!.selectionStyle = UITableViewCellSelectionStyle.none + cell!.selectionStyle = UITableViewCell.SelectionStyle.none return cell! } } diff --git a/KSTokenView/KSUtils.swift b/KSTokenView/KSUtils.swift index d754287..18d7c1b 100644 --- a/KSTokenView/KSUtils.swift +++ b/KSTokenView/KSUtils.swift @@ -31,19 +31,19 @@ class KSUtils : NSObject { class func getRect(_ str: NSString, width: CGFloat, height: CGFloat, font: UIFont) -> CGRect { let rectangleStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle rectangleStyle.alignment = NSTextAlignment.center - let rectangleFontAttributes = [NSAttributedStringKey.font: font, NSAttributedStringKey.paragraphStyle: rectangleStyle] + let rectangleFontAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.paragraphStyle: rectangleStyle] return str.boundingRect(with: CGSize(width: width, height: height), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: rectangleFontAttributes, context: nil) } class func getRect(_ str: NSString, width: CGFloat, font: UIFont) -> CGRect { let rectangleStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle rectangleStyle.alignment = NSTextAlignment.center - let rectangleFontAttributes = [NSAttributedStringKey.font: font, NSAttributedStringKey.paragraphStyle: rectangleStyle] + let rectangleFontAttributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.paragraphStyle: rectangleStyle] return str.boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: rectangleFontAttributes, context: nil) } class func widthOfString(_ str: String, font: UIFont) -> CGFloat { - let attrs = [NSAttributedStringKey.font: font] + let attrs = [NSAttributedString.Key.font: font] let attributedString = NSMutableAttributedString(string:str, attributes:attrs) return attributedString.size().width }