-
Notifications
You must be signed in to change notification settings - Fork 379
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
Swift 4 #457
Swift 4 #457
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,7 +349,8 @@ class StringTests: XCTestCase { | |
let testString = "H3yH0L3tsG0" | ||
let expectedResult = ["3","0","3","0"] | ||
|
||
XCTAssertEqual(testString.matchesForRegexInText("[0-9]"), expectedResult) | ||
// XCTAssertEqual(testString.matchesForRegexInText("[0-9]"), expectedResult) | ||
XCTFail() | ||
} | ||
|
||
func testIsNumber() { | ||
|
@@ -371,16 +372,16 @@ class StringTests: XCTestCase { | |
let testString = "meh" | ||
let testString2 = "✅" | ||
|
||
let boldResult = NSAttributedString(string: testString, attributes: [NSFontAttributeName: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let boldResult2 = NSAttributedString(string: testString2, attributes: [NSFontAttributeName: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let underlineResult = NSAttributedString(string: testString, attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue]) | ||
let underlineResult2 = NSAttributedString(string: testString2, attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue]) | ||
let boldResult = NSAttributedString(string: testString, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a new lint thing? Or did you interject these spaces accidentally? |
||
let boldResult2 = NSAttributedString(string: testString2, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let underlineResult = NSAttributedString(string: testString, attributes: [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) | ||
let underlineResult2 = NSAttributedString(string: testString2, attributes: [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) | ||
|
||
let italicResult = NSAttributedString(string: testString, attributes: [NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let italicResult2 = NSAttributedString(string: testString2, attributes: [NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let italicResult = NSAttributedString(string: testString, attributes: [NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let italicResult2 = NSAttributedString(string: testString2, attributes: [NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
|
||
let colorResult = NSAttributedString(string: testString, attributes: [NSForegroundColorAttributeName: UIColor.green]) | ||
let colorResult2 = NSAttributedString(string: testString2, attributes: [NSForegroundColorAttributeName: UIColor.green]) | ||
let colorResult = NSAttributedString(string: testString, attributes: [NSAttributedStringKey.foregroundColor: UIColor.green]) | ||
let colorResult2 = NSAttributedString(string: testString2, attributes: [NSAttributedStringKey.foregroundColor: UIColor.green]) | ||
|
||
XCTAssertEqual(testString.bold(), boldResult) | ||
XCTAssertEqual(testString.underline(), underlineResult) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ extension Array { | |
var j: Int | ||
for i in 0..<(count-2) { | ||
j = Int(arc4random_uniform(UInt32(count - i))) | ||
if i != i+j { swap(&self[i], &self[i+j]) } | ||
if i != i+j { self.swapAt(i, i+j) } | ||
} | ||
} | ||
|
||
|
@@ -220,7 +220,7 @@ extension Array where Element: Hashable { | |
extension Collection where Indices.Iterator.Element == Index { | ||
|
||
/// Returns the element at the specified index if it is within bounds, otherwise nil. | ||
public subscript (safe index: Index) -> Generator.Element? { | ||
public subscript (safe index: Index) -> Iterator.Element? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats the difference? |
||
return indices.contains(index) ? self[index] : nil | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ extension Dictionary { | |
public func union(_ dictionaries: Dictionary...) -> Dictionary { | ||
var result = self | ||
dictionaries.forEach { (dictionary) -> Void in | ||
dictionary.forEach { (key, value) -> Void in | ||
dictionary.forEach { (arg) -> Void in | ||
|
||
let (key, value) = arg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary in swift 4 syntax? IMO the earlier version looked cleaner. |
||
result[key] = value | ||
} | ||
} | ||
|
@@ -38,9 +40,11 @@ extension Dictionary { | |
} | ||
|
||
// Intersection | ||
return filtered.filter { (key: K, value: V) -> Bool in | ||
return filtered.filter { (arg: (key: K, value: V)) -> Bool in | ||
// check for [key: value] in all the dictionaries | ||
dictionaries.testAll { $0.has(key) && $0[key] == value } | ||
|
||
let (key, value) = arg | ||
return dictionaries.testAll { $0.has(key) && $0[key] == value } | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ extension String { | |
public subscript(integerRange: Range<Int>) -> String { | ||
let start = characters.index(startIndex, offsetBy: integerRange.lowerBound) | ||
let end = characters.index(startIndex, offsetBy: integerRange.upperBound) | ||
return self[start..<end] | ||
return String(self[start..<end]) | ||
} | ||
|
||
/// EZSE: Cut string from closedrange | ||
|
@@ -257,22 +257,22 @@ extension String { | |
return (regex?.numberOfMatches(in: str, options: NSRegularExpression.MatchingOptions(), range: NSRange(location:0, length: str.length)) ?? -1) + 1 | ||
} | ||
|
||
internal func rangeFromNSRange(_ nsRange: NSRange) -> Range<String.Index>? { | ||
let from16 = utf16.startIndex.advanced(by: nsRange.location) | ||
let to16 = from16.advanced(by: nsRange.length) | ||
if let from = String.Index(from16, within: self), | ||
let to = String.Index(to16, within: self) { | ||
return from ..< to | ||
} | ||
return nil | ||
} | ||
// internal func rangeFromNSRange(_ nsRange: NSRange) -> Range<String.Index>? { | ||
// let from16 = utf16.startIndex + nsRange.location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put TODO here and the next method that they will be uncommented later. |
||
// let to16 = from16 + nsRange.length | ||
// if let from = String.Index(from16, within: self), | ||
// let to = String.Index(to16, within: self) { | ||
// return from ..< to | ||
// } | ||
// return nil | ||
// } | ||
|
||
/// EZSE: Find matches of regular expression in string | ||
public func matchesForRegexInText(_ regex: String!) -> [String] { | ||
let regex = try? NSRegularExpression(pattern: regex, options: []) | ||
let results = regex?.matches(in: self, options: [], range: NSRange(location: 0, length: self.length)) ?? [] | ||
return results.map { self.substring(with: self.rangeFromNSRange($0.range)!) } | ||
} | ||
// public func matchesForRegexInText(_ regex: String!) -> [String] { | ||
// let regex = try? NSRegularExpression(pattern: regex, options: []) | ||
// let results = regex?.matches(in: self, options: [], range: NSRange(location: 0, length: self.length)) ?? [] | ||
// return results.map { self.substring(with: self.rangeFromNSRange($0.range)!) } | ||
// } | ||
|
||
/// EZSE: Checks if String contains Email | ||
public var isEmail: Bool { | ||
|
@@ -368,23 +368,23 @@ extension String { | |
|
||
///EZSE: Returns bold NSAttributedString | ||
public func bold() -> NSAttributedString { | ||
let boldString = NSMutableAttributedString(string: self, attributes: [NSFontAttributeName: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let boldString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)]) | ||
return boldString | ||
} | ||
|
||
#endif | ||
|
||
///EZSE: Returns underlined NSAttributedString | ||
public func underline() -> NSAttributedString { | ||
let underlineString = NSAttributedString(string: self, attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue]) | ||
let underlineString = NSAttributedString(string: self, attributes: [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) | ||
return underlineString | ||
} | ||
|
||
#if os(iOS) | ||
|
||
///EZSE: Returns italic NSAttributedString | ||
public func italic() -> NSAttributedString { | ||
let italicString = NSMutableAttributedString(string: self, attributes: [NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
let italicString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.font: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) | ||
return italicString | ||
} | ||
|
||
|
@@ -393,24 +393,24 @@ extension String { | |
#if os(iOS) | ||
|
||
///EZSE: Returns hight of rendered string | ||
public func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat { | ||
var attrib: [String: AnyObject] = [NSFontAttributeName: font] | ||
if lineBreakMode != nil { | ||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.lineBreakMode = lineBreakMode! | ||
attrib.updateValue(paragraphStyle, forKey: NSParagraphStyleAttributeName) | ||
} | ||
let size = CGSize(width: width, height: CGFloat(Double.greatestFiniteMagnitude)) | ||
return ceil((self as NSString).boundingRect(with: size, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attrib, context: nil).height) | ||
} | ||
// public func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put TODO here to uncomment it later on. |
||
// var attrib: [String: AnyObject] = [NSAttributedStringKey.font.rawValue: font] | ||
// if lineBreakMode != nil { | ||
// let paragraphStyle = NSMutableParagraphStyle() | ||
// paragraphStyle.lineBreakMode = lineBreakMode! | ||
// attrib.updateValue(paragraphStyle, forKey: NSAttributedStringKey.paragraphStyle.rawValue) | ||
// } | ||
// let size = CGSize(width: width, height: CGFloat(Double.greatestFiniteMagnitude)) | ||
// return ceil((self as NSString).boundingRect(with: size, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attrib, context: nil).height) | ||
// } | ||
|
||
#endif | ||
|
||
#if os(iOS) || os(tvOS) | ||
|
||
///EZSE: Returns NSAttributedString | ||
public func color(_ color: UIColor) -> NSAttributedString { | ||
let colorString = NSMutableAttributedString(string: self, attributes: [NSForegroundColorAttributeName: color]) | ||
let colorString = NSMutableAttributedString(string: self, attributes: [NSAttributedStringKey.foregroundColor: color]) | ||
return colorString | ||
} | ||
|
||
|
@@ -429,7 +429,7 @@ extension String { | |
} | ||
let attrText = NSMutableAttributedString(string: self) | ||
for range in ranges { | ||
attrText.addAttribute(NSForegroundColorAttributeName, value: color, range: range) | ||
attrText.addAttribute(NSAttributedStringKey.foregroundColor, value: color, range: range) | ||
} | ||
return attrText | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets put TODOs here and everywhere else we have interjected a deliberate Fail.