Skip to content

Commit

Permalink
update to Swift version 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
younatics committed Feb 8, 2019
1 parent ccca0c5 commit f107d02
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.2
4 changes: 2 additions & 2 deletions Highlighter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Highlighter'
s.version = '1.2.0'
s.version = '1.3.0'
s.summary = 'Highlight whatever you want!'

s.description = <<-DESC
Expand All @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/younatics/Highlighter.git', :tag => s.version.to_s }
s.source_files = 'Highlighter/*.swift'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'
s.frameworks = 'Foundation'
s.requires_arc = true
end
12 changes: 6 additions & 6 deletions Highlighter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -262,11 +262,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -292,7 +292,7 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -313,7 +313,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.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>
4 changes: 2 additions & 2 deletions Highlighter/Highlightable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public protocol Highlightable: class {
var textValue: String? { get }
var attributedTextValue: NSAttributedString? { get set }

func highlight(text: String, normal normalAttributes: [NSAttributedStringKey : Any]?, highlight highlightAttributes: [NSAttributedStringKey : Any]?)
func highlight(text: String, normal normalAttributes: [NSAttributedString.Key : Any]?, highlight highlightAttributes: [NSAttributedString.Key : Any]?)
}

extension Highlightable {
public func highlight(text: String, normal normalAttributes: [NSAttributedStringKey : Any]?, highlight highlightAttributes: [NSAttributedStringKey : Any]?) {
public func highlight(text: String, normal normalAttributes: [NSAttributedString.Key : Any]?, highlight highlightAttributes: [NSAttributedString.Key : Any]?) {
guard let inputText = self.textValue else { return }

let highlightRanges = inputText.lowercased().ranges(of: text)
Expand Down
4 changes: 2 additions & 2 deletions Highlighter/HighlightableContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public protocol HighlightableContainer: class {
/// - normalAttributes: Attributes to apply to non-matching text
/// - highlightAttributes: Attributes to apply (highlight) to matching text
/// - type: (optional) Only search `Highlightable`s of this type
func highlight(text: String, normal normalAttributes: [NSAttributedStringKey : Any]?, highlight highlightAttributes: [NSAttributedStringKey : Any]?, type: Highlightable.Type?)
func highlight(text: String, normal normalAttributes: [NSAttributedString.Key : Any]?, highlight highlightAttributes: [NSAttributedString.Key : Any]?, type: Highlightable.Type?)
}

extension HighlightableContainer {
public func highlight(text: String, normal normalAttributes: [NSAttributedStringKey : Any]?, highlight highlightAttributes: [NSAttributedStringKey : Any]?, type: Highlightable.Type? = nil) {
public func highlight(text: String, normal normalAttributes: [NSAttributedString.Key : Any]?, highlight highlightAttributes: [NSAttributedString.Key : Any]?, type: Highlightable.Type? = nil) {
let mirror = Mirror(reflecting: self)
mirror.children
.flatMap { $0.value as? Highlightable }
Expand Down
8 changes: 4 additions & 4 deletions Highlighter/NSAttributedString+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

extension NSAttributedString {
static func highlight(ranges: [Range<String.Index>], at searchText: String, in originText: String, normal normalAttributes: [NSAttributedStringKey : Any]?, highlight highlightAttributes: [NSAttributedStringKey : Any]?) -> NSAttributedString {
static func highlight(ranges: [Range<String.Index>], at searchText: String, in originText: String, normal normalAttributes: [NSAttributedString.Key : Any]?, highlight highlightAttributes: [NSAttributedString.Key : Any]?) -> NSAttributedString {
let startString = String(originText[..<ranges[0].lowerBound])
let highlightString = NSMutableAttributedString(string: startString, attributes: normalAttributes)

Expand All @@ -30,20 +30,20 @@ extension NSAttributedString {
return highlightString
}

private static func continueAttribute(originText: String, upperBound: String.Index, lowerBound: String.Index, normalAttributes: [NSAttributedStringKey : Any]?) -> NSMutableAttributedString {
private static func continueAttribute(originText: String, upperBound: String.Index, lowerBound: String.Index, normalAttributes: [NSAttributedString.Key : Any]?) -> NSMutableAttributedString {
let range = Range(uncheckedBounds: (upperBound, lowerBound))
let continueString = String(originText[range])
let continueAttributeString = NSMutableAttributedString(string: continueString, attributes: normalAttributes)
return continueAttributeString
}

private static func containAttribute(originText: String, bound: Range<String.Index>, attributes: [NSAttributedStringKey : Any]?) -> NSMutableAttributedString {
private static func containAttribute(originText: String, bound: Range<String.Index>, attributes: [NSAttributedString.Key : Any]?) -> NSMutableAttributedString {
let containedString = String(originText[bound])
let containedAttributeString = NSMutableAttributedString(string: containedString, attributes: attributes)
return containedAttributeString
}

private static func endAttribute(originText: String, bound: String.Index, normalAttributes: [NSAttributedStringKey : Any]?) -> NSMutableAttributedString {
private static func endAttribute(originText: String, bound: String.Index, normalAttributes: [NSAttributedString.Key : Any]?) -> NSMutableAttributedString {
let endString = String(originText[bound...])
let endAttributeString = NSMutableAttributedString(string: endString, attributes: normalAttributes)
return endAttributeString
Expand Down

0 comments on commit f107d02

Please sign in to comment.