diff --git a/.swift-version b/.swift-version index 9f55b2c..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.0 diff --git a/.travis.yml b/.travis.yml index 591aafc..eda2dc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ # * https://github.com/supermarin/xcpretty#usage language: objective-c # still specify this even though we are using swift - appears to tell travis which Xcode version to use -osx_image: xcode8 +osx_image: xcode9.1 #cache: cocoapods podfile: Example/Podfile before_install: @@ -15,7 +15,7 @@ script: - set -o pipefail - xcodebuild -version - xcodebuild -showsdks -- xcodebuild build test -workspace Example/FazeKit.xcworkspace -scheme FazeKit-Example -sdk iphonesimulator10.0 -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0' ONLY_ACTIVE_ARCH=NO | xcpretty +- xcodebuild build test -workspace Example/FazeKit.xcworkspace -scheme FazeKit-Example -destination 'platform=iOS Simulator,name=iPhone SE' ONLY_ACTIVE_ARCH=NO | xcpretty - pod lib lint notifications: slack: diff --git a/Example/FazeKit.xcodeproj/project.pbxproj b/Example/FazeKit.xcodeproj/project.pbxproj index 68f49fd..999d6a0 100644 --- a/Example/FazeKit.xcodeproj/project.pbxproj +++ b/Example/FazeKit.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 607FACEC1AFB9204008FA782 /* UIViewAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */; }; 78B6DD4BAF21BA4B263F3EF4 /* Pods_FazeKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DB0AD919FBE4556CA363D8B /* Pods_FazeKit_Tests.framework */; }; + 7CDA2BCA1FE872FE00CBA532 /* StringAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */; }; C20FAFE21DD42EAA009E5C3F /* MulticastTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */; }; C2B9A0321DD29F9100AF4E04 /* DateAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */; }; C2B9A0381DD2DAE500AF4E04 /* CollectionAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B9A0361DD2DAB500AF4E04 /* CollectionAdditionsTests.swift */; }; @@ -45,6 +46,7 @@ 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewAdditionsTests.swift; sourceTree = ""; }; 739B56FA57C1D0E13427B629 /* Pods-FazeKit_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FazeKit_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-FazeKit_Tests/Pods-FazeKit_Tests.release.xcconfig"; sourceTree = ""; }; + 7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringAdditionsTests.swift; sourceTree = ""; }; AE54F13DF076B827802B2E27 /* Pods-FazeKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FazeKit_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FazeKit_Example/Pods-FazeKit_Example.debug.xcconfig"; sourceTree = ""; }; C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulticastTests.swift; sourceTree = ""; }; C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateAdditionsTests.swift; sourceTree = ""; }; @@ -133,6 +135,7 @@ C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */, C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */, C2E94BAD1D62CDD5007A7A4C /* ProcessInfoAdditionsTests.swift */, + 7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */, 607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */, 607FACE91AFB9204008FA782 /* Supporting Files */, ); @@ -384,6 +387,7 @@ 607FACEC1AFB9204008FA782 /* UIViewAdditionsTests.swift in Sources */, C2B9A0321DD29F9100AF4E04 /* DateAdditionsTests.swift in Sources */, C20FAFE21DD42EAA009E5C3F /* MulticastTests.swift in Sources */, + 7CDA2BCA1FE872FE00CBA532 /* StringAdditionsTests.swift in Sources */, C2B9A0381DD2DAE500AF4E04 /* CollectionAdditionsTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 4ea8152..e4d042e 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -49,7 +49,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 00C4305ADAD279636C1C96176AE4BC73 /* FazeKit.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = FazeKit.modulemap; sourceTree = ""; }; + 00C4305ADAD279636C1C96176AE4BC73 /* FazeKit.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = FazeKit.modulemap; sourceTree = ""; }; 0A1AAFF75E2CC46A652C80064951AE06 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 165CB0A62C8FE9EEA4232D1580357D91 /* DateAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DateAdditions.swift; sourceTree = ""; }; 19587F9E62528DFFB17175BFD82BBC03 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -59,9 +59,9 @@ 39A1F876BD07B051DFFC141AAA79828B /* DateComponentAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DateComponentAdditions.swift; sourceTree = ""; }; 43C467D8F6ED457259EB2B5548FEFBE3 /* Pods-FazeKit_Example-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-FazeKit_Example-acknowledgements.markdown"; sourceTree = ""; }; 4D9F97B3143EF51F4505B645A119EA92 /* UIScreenAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIScreenAdditions.swift; sourceTree = ""; }; - 52C81A729DAA2801C0B6ACABDB5C4A89 /* FazeKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = FazeKit.framework; path = FazeKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 55808AB1308422B28E9108292A9F3314 /* Pods_FazeKit_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_FazeKit_Tests.framework; path = "Pods-FazeKit_Tests.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; - 5C4C5D322F0358C80BCEC19157F4E7CD /* Pods_FazeKit_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_FazeKit_Example.framework; path = "Pods-FazeKit_Example.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 52C81A729DAA2801C0B6ACABDB5C4A89 /* FazeKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FazeKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 55808AB1308422B28E9108292A9F3314 /* Pods_FazeKit_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FazeKit_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5C4C5D322F0358C80BCEC19157F4E7CD /* Pods_FazeKit_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FazeKit_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5DDC20002A39692064207768B22006B3 /* UIDeviceAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIDeviceAdditions.swift; sourceTree = ""; }; 5E6A5A7016F731509F413A486D94ED4B /* Multicast.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = Multicast.swift; sourceTree = ""; }; 616BEB51ECCAD129BDBCB7A956B56CC6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; @@ -74,9 +74,9 @@ 71580B7CBD31FEF9F84979C3944AF131 /* FazeKit-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "FazeKit-dummy.m"; sourceTree = ""; }; 74A821119B852AFAA2F7723CC65695B2 /* UIImageAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIImageAdditions.swift; sourceTree = ""; }; 7EC994CDC2D681BA26389F78A7E4B325 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - 8EABB261BDBA5DDF9D167316E4C0515F /* Pods-FazeKit_Example.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = "Pods-FazeKit_Example.modulemap"; sourceTree = ""; }; + 8EABB261BDBA5DDF9D167316E4C0515F /* Pods-FazeKit_Example.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = "Pods-FazeKit_Example.modulemap"; sourceTree = ""; }; 92C0D4F4CF121BD9E515180D1187C2F9 /* Pods-FazeKit_Example-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-FazeKit_Example-resources.sh"; sourceTree = ""; }; - 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 9B97F9BC455B6B25280470AC0722FE05 /* Pods-FazeKit_Example-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-FazeKit_Example-frameworks.sh"; sourceTree = ""; }; A1CD940A8AD4FA777BE306168B504ACD /* Pods-FazeKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-FazeKit_Example.release.xcconfig"; sourceTree = ""; }; A1FEDE77480A01A2AC3F1BF93896358F /* Pods-FazeKit_Example-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-FazeKit_Example-umbrella.h"; sourceTree = ""; }; @@ -84,7 +84,7 @@ C34AC1758779CFB9CF4DB4A37BF7BCA1 /* UIViewAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIViewAdditions.swift; sourceTree = ""; }; CE2AD7B44607FA2CB0CD55F74EA74ECE /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; D38757DECB6D6DFF9F71A77396712127 /* FazeKit-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "FazeKit-prefix.pch"; sourceTree = ""; }; - DABD955476B4AF5E3CD17DD838590F1D /* Pods-FazeKit_Tests.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; path = "Pods-FazeKit_Tests.modulemap"; sourceTree = ""; }; + DABD955476B4AF5E3CD17DD838590F1D /* Pods-FazeKit_Tests.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = "Pods-FazeKit_Tests.modulemap"; sourceTree = ""; }; EA40B0976A4099B309E061EA33E4FE9D /* FazeKit.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = FazeKit.xcconfig; sourceTree = ""; }; EBD7F67205EFBE8E843D34C967EA2AA8 /* CollectionAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CollectionAdditions.swift; sourceTree = ""; }; EBE40F45D207E074F017986DDA4E64E7 /* UIColorAdditions.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIColorAdditions.swift; sourceTree = ""; }; @@ -155,7 +155,6 @@ children = ( 8E439C458EBEC50EBC62DEBA909FCF2E /* Classes */, ); - name = FazeKit; path = FazeKit; sourceTree = ""; }; @@ -208,7 +207,6 @@ 4D9F97B3143EF51F4505B645A119EA92 /* UIScreenAdditions.swift */, C34AC1758779CFB9CF4DB4A37BF7BCA1 /* UIViewAdditions.swift */, ); - name = Classes; path = Classes; sourceTree = ""; }; @@ -359,6 +357,11 @@ attributes = { LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0700; + TargetAttributes = { + F329D64FF0977CD5D7239556A19E63F1 = { + LastSwiftMigration = 0900; + }; + }; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -530,7 +533,8 @@ PRODUCT_NAME = FazeKit; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -678,7 +682,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Example/Tests/StringAdditionsTests.swift b/Example/Tests/StringAdditionsTests.swift new file mode 100644 index 0000000..cee7df1 --- /dev/null +++ b/Example/Tests/StringAdditionsTests.swift @@ -0,0 +1,67 @@ +// +// Copyright 2017 NextFaze +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations +// under the License. +// +// StringAdditionsTests.swift +// FazeKit_Tests +// +// Created by Ricardo Santos on 19/12/17. +// + +import Foundation +import XCTest +import FazeKit + +class StringAdditionsTests: XCTestCase { + + override func setUp() { + super.setUp() + } + + override func tearDown() { + super.tearDown() + } + + func testContains() { + let string = "Abcdefgh" + XCTAssertTrue(string.contains("A"), "String.contains: should have found a match") + XCTAssertFalse(string.contains("a"), "String.contains: should not have found a match") + XCTAssertFalse(string.contains("z"), "String.contains: should not have found a match") + } + + func testReplace() { + var string = "The cat jumped over the hat" + string = string.replace("cat", withString: "dog") + XCTAssertTrue(string.contains("dog"), "String.replace: should contain the replacement substring") + XCTAssertFalse(string.contains("cat"), "String.replace: should not still contain the original substring") + } + + func testSubscript() { + let string = "OMG. I can't believe it's a thing!" + XCTAssertTrue(string[0] == "O", "String.subscript: should return the Character O") + XCTAssertTrue(string[1] == "M", "String.subscript: should return the Character M") + XCTAssertTrue(string[2] == "G", "String.subscript: should return the Character G") + } + + func testSubstring() { + let string = "OMG. Is this even a thing?" + XCTAssertTrue(string.substring(0, length: 3) == "OMG", "String.substring: should create a new substring") + } + + func testTrim() { + let string = " Hello World \n\n\n " + XCTAssertTrue(string.trim() == "Hello World", "String.trim(): should remove all whitespace and newlines") + } + +} diff --git a/FazeKit/Classes/CollectionAdditions.swift b/FazeKit/Classes/CollectionAdditions.swift index ff5c9ef..093f146 100644 --- a/FazeKit/Classes/CollectionAdditions.swift +++ b/FazeKit/Classes/CollectionAdditions.swift @@ -56,24 +56,24 @@ public extension Sequence { } } -public func +(lhs: Dictionary, rhs: Dictionary) -> Dictionary { +public func +(lhs: Dictionary, rhs: Dictionary) -> Dictionary { var dict = Dictionary() lhs.forEach { dict[$0.key] = $0.value } rhs.forEach { dict[$0.key] = $0.value } return dict } -public func -(lhs: Dictionary, rhs: Dictionary) -> Dictionary { +public func -(lhs: Dictionary, rhs: Dictionary) -> Dictionary { var dict = Dictionary() lhs.forEach { dict[$0.key] = $0.value } rhs.forEach { dict.removeValue(forKey: $0.key) } return dict } -public func +=(lhs: inout Dictionary, rhs: Dictionary) { +public func +=(lhs: inout Dictionary, rhs: Dictionary) { rhs.forEach { lhs[$0.key] = $0.value } } -public func -=(lhs: inout Dictionary, rhs: Dictionary) { +public func -=(lhs: inout Dictionary, rhs: Dictionary) { rhs.forEach { lhs.removeValue(forKey: $0.key) } } diff --git a/FazeKit/Classes/StringAdditions.swift b/FazeKit/Classes/StringAdditions.swift index 88252b7..d3a136f 100644 --- a/FazeKit/Classes/StringAdditions.swift +++ b/FazeKit/Classes/StringAdditions.swift @@ -22,8 +22,10 @@ // gist: https://gist.github.com/albertbori/0faf7de867d96eb83591 // stackoverflow: http://stackoverflow.com/questions/27570910/swift-fast-low-level-string-lastindexof public extension String { + + @available(*, deprecated, message: "Use count instead") public var length: Int { - return self.characters.count + return self.count } public func contains(_ s: String) -> Bool { @@ -35,52 +37,37 @@ public extension String { } public subscript(i: Int) -> Character { - return self[self.characters.index(self.startIndex, offsetBy: i)] - } - - public subscript(r: Range) -> String { - let startIndex = self.characters.index(self.startIndex, offsetBy: max(0, r.lowerBound)) - let endIndex = self.characters.index(self.startIndex, offsetBy: min(self.length, r.upperBound)) - return self[startIndex.. Range? { - let from16 = utf16.index(utf16.startIndex, offsetBy: nsRange.location, limitedBy: utf16.endIndex) ?? utf16.endIndex - let to16 = utf16.index(from16, offsetBy: nsRange.length, limitedBy: utf16.endIndex) ?? utf16.endIndex - if let from = String.Index(from16, within: self), - let to = String.Index(to16, within: self) { - return from ..< to - } - return nil - } public func substring(_ startIndex: Int, length: Int) -> String { - let start = self.characters.index(self.startIndex, offsetBy: startIndex) - let end = self.characters.index(start, offsetBy: length) - return self.substring(with: start.. Int? { guard let range = self.range(of: target) else { return nil } - return self.characters.distance(from: self.startIndex, to: range.lowerBound) + return self.distance(from: self.startIndex, to: range.lowerBound) } public func indexOf(_ target: String, startIndex: Int) -> Int? { - let startRange = self.characters.index(self.startIndex, offsetBy: startIndex) + let startRange = self.index(self.startIndex, offsetBy: startIndex) guard let range = self.range(of: target, options: NSString.CompareOptions.literal, range: startRange.. Int? { guard let range: Range = self.range(of: target, options: .backwards) else { return nil } - return self.characters.distance(from: self.startIndex, to: range.lowerBound) + return self.distance(from: self.startIndex, to: range.lowerBound) } public func isMatch(_ regex: String, options: NSRegularExpression.Options) -> Bool { do { let exp = try NSRegularExpression(pattern: regex, options: options) - return exp.numberOfMatches(in: self, options: [], range: NSMakeRange(0, self.length)) > 0 + return exp.numberOfMatches(in: self, options: [], range: NSMakeRange(0, self.count)) > 0 } catch { return false } @@ -90,7 +77,7 @@ public extension String { do { let exp = try NSRegularExpression(pattern: regex, options: options) let nsString = self as NSString - let results = exp.matches(in: self, options: [], range: NSMakeRange(0, self.length)) + let results = exp.matches(in: self, options: [], range: NSMakeRange(0, self.count)) return results.map{nsString.substring(with: $0.range)} } catch { return [] @@ -100,4 +87,5 @@ public extension String { public func trim() -> String { return self.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) } + } diff --git a/FazeKit/Classes/UIColorAdditions.swift b/FazeKit/Classes/UIColorAdditions.swift index 373660c..7d65a32 100644 --- a/FazeKit/Classes/UIColorAdditions.swift +++ b/FazeKit/Classes/UIColorAdditions.swift @@ -34,7 +34,7 @@ public extension UIColor { var int = UInt32() Scanner(string: hex).scanHexInt32(&int) let r, g, b: UInt32 - switch hex.characters.count { + switch hex.count { case 3: // RGB (12-bit) (r, g, b) = ((int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) case 6: // RGB (24-bit)