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

Updated Repository to Swift 4.2 #112

Open
wants to merge 1 commit into
base: master
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
10 changes: 7 additions & 3 deletions Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0910;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Khawar Shahzad";
TargetAttributes = {
C389780A1DFB1FB3009E3D81 = {
Expand Down Expand Up @@ -244,13 +244,15 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand Down Expand Up @@ -300,13 +302,15 @@
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;
CLANG_WARN_ENUM_CONVERSION = YES;
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;
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/ViewControllers/Horizontal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Horizontal: UIViewController {

extension Horizontal: KSTokenViewDelegate {
func tokenView(_ tokenView: KSTokenView, performSearchWithString string: String, completion: ((_ results: Array<AnyObject>) -> Void)?) {
if (string.characters.isEmpty){
if (string.isEmpty){
completion!(names as Array<AnyObject>)
return
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/ViewControllers/ObjectiveC.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/ViewControllers/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class StackView: UIViewController {

extension StackView: KSTokenViewDelegate {
func tokenView(_ tokenView: KSTokenView, performSearchWithString string: String, completion: ((_ results: Array<AnyObject>) -> Void)?) {
if (string.characters.isEmpty){
if (string.isEmpty){
completion!(names as Array<AnyObject>)
return
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/ViewControllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion KSTokenView/KSToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions KSTokenView/KSTokenField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions KSTokenView/KSTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
//__________________________________________________________________________________
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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!
}
}
6 changes: 3 additions & 3 deletions KSTokenView/KSUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down