diff --git a/.travis.yml b/.travis.yml index 2b5d4c0..c3e93d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ -language: objective-c -osx_image: xcode8.1 +language: swift +osx_image: xcode10 script: - cd Example/ - pod install - cd .. - - xcodebuild -scheme Analysis_Tests -workspace Example/Analysis.xcworkspace -configuration Debug build test -destination "platform=iOS Simulator,name=iPhone 6" + - xcodebuild clean test -scheme Analysis_Tests -workspace Example/Analysis.xcworkspace -destination "platform=iOS Simulator,name=iPhone X,OS=12.0" diff --git a/Analysis.podspec b/Analysis.podspec index 9f64e44..185e6ad 100644 --- a/Analysis.podspec +++ b/Analysis.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Analysis" - s.version = "0.2.0" + s.version = "0.3.0" s.summary = "Analyse your strings." s.description = <<-DESC diff --git a/Analysis/Classes/Analysis.swift b/Analysis/Classes/Analysis.swift index a4599a5..40f557a 100644 --- a/Analysis/Classes/Analysis.swift +++ b/Analysis/Classes/Analysis.swift @@ -31,11 +31,10 @@ public struct Analysis { .replacingOccurrences(of: ". ", with: ".\n") .replacingOccurrences(of: "? ", with: "?\n").lines .filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty } - words = input.characters + words = input .split(separator: " ") - .map(String.init) .map { $0.trimmingCharacters(in: CharacterSet.letters.inverted) } - characters = Array(input.characters) + characters = Array(input) } /// Returns the sentence count of the `input`. @@ -180,10 +179,10 @@ public struct Analysis { public func averageCharacters(per option: LengthOption) -> Double { switch option { case .word: - return Double(words.reduce("", +).characters.count) / Double(wordCount()) + return Double(words.reduce("", +).count) / Double(wordCount()) case .sentence: if sentences.count > 1 { - return Double(sentences.reduce("", +).characters.count) / Double(sentenceCount()) + return Double(sentences.reduce("", +).count) / Double(sentenceCount()) } else { return Double(characterCount(includingSpaces: true)) / Double(sentenceCount()) } diff --git a/Analysis/Classes/Dictionary+Sorting.swift b/Analysis/Classes/Dictionary+Sorting.swift index aa6267a..5201820 100644 --- a/Analysis/Classes/Dictionary+Sorting.swift +++ b/Analysis/Classes/Dictionary+Sorting.swift @@ -25,16 +25,16 @@ extension Dictionary where Key: Comparable, Value: Comparable { case .key: switch direction { case .ascending: - return sorted { $0.0.key < $0.1.key } + return sorted { $0.key < $1.key } case .descending: - return sorted { $0.0.key > $0.1.key } + return sorted { $0.key > $1.key } } case .value: switch direction { case .ascending: - return sorted { $0.0.value < $0.1.value } + return sorted { $0.value < $1.value } case .descending: - return sorted { $0.0.value > $0.1.value } + return sorted { $0.value > $1.value } } } } diff --git a/Analysis/Classes/SyllableCounter.swift b/Analysis/Classes/SyllableCounter.swift index 16d4042..bc9d81e 100755 --- a/Analysis/Classes/SyllableCounter.swift +++ b/Analysis/Classes/SyllableCounter.swift @@ -152,8 +152,8 @@ public class SyllableCounter { // MARK: - Public methods internal func count(word: String) -> Int { - if word.characters.count <= 1 { - return word.characters.count + if word.count <= 1 { + return word.count } var mutatedWord = word.lowercased(with: Locale(identifier: "en_US")).trimmingCharacters(in: .punctuationCharacters) @@ -162,14 +162,14 @@ public class SyllableCounter { return exceptionValue } - if mutatedWord.characters.last == "e" { - mutatedWord = String(mutatedWord.characters.dropLast()) + if mutatedWord.last == "e" { + mutatedWord = String(mutatedWord.dropLast()) } var count = 0 var previousIsVowel = false - for character in mutatedWord.characters { + for character in mutatedWord { let isVowel = vowels.contains(character) if isVowel && !previousIsVowel { count += 1 @@ -178,14 +178,14 @@ public class SyllableCounter { } for pattern in addSyllables { - let matches = pattern.matches(in: mutatedWord, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: mutatedWord.characters.count)) + let matches = pattern.matches(in: mutatedWord, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: mutatedWord.count)) if !matches.isEmpty { count += 1 } } for pattern in subSyllables { - let matches = pattern.matches(in: mutatedWord, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: mutatedWord.characters.count)) + let matches = pattern.matches(in: mutatedWord, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: mutatedWord.count)) if !matches.isEmpty { count -= 1 } diff --git a/Changelog.md b/Changelog.md index c521830..6905808 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # next +# [0.3.0](https://github.com/BasThomas/Analysis/releases/tag/0.3.0) + +- Updated to Swift 4.2. + # [0.2.0](https://github.com/BasThomas/Analysis/releases/tag/0.2.0) - Added `syllableCount()`, which counts the total amount of syllables of the `input`. diff --git a/Example/Analysis.xcodeproj/project.pbxproj b/Example/Analysis.xcodeproj/project.pbxproj index af3fe5d..cb0d138 100644 --- a/Example/Analysis.xcodeproj/project.pbxproj +++ b/Example/Analysis.xcodeproj/project.pbxproj @@ -222,16 +222,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = "Bas Broek"; TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1000; }; 607FACE41AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1000; TestTargetID = 607FACCF1AFB9204008FA782; }; }; @@ -298,13 +298,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Analysis_Example-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 9720F7DDF7A6499D6392BC2D /* [CP] Check Pods Manifest.lock */ = { @@ -313,13 +316,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Analysis_Tests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; B726F347928269BC02F4A2CC /* [CP] Embed Pods Frameworks */ = { @@ -328,9 +334,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Analysis_Example/Pods-Analysis_Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Analysis/Analysis.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Analysis.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -428,14 +437,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 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_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; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -475,14 +492,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 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_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; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -518,7 +543,8 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -533,7 +559,8 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -553,7 +580,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Analysis_Example.app/Analysis_Example"; }; name = Debug; @@ -570,7 +598,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Analysis_Example.app/Analysis_Example"; }; name = Release; diff --git a/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis-Example.xcscheme b/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis-Example.xcscheme index 0d0fd97..a11e1eb 100644 --- a/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis-Example.xcscheme +++ b/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis-Example.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis_Tests.xcscheme b/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis_Tests.xcscheme index 31806b6..f20ea9d 100644 --- a/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis_Tests.xcscheme +++ b/Example/Analysis.xcodeproj/xcshareddata/xcschemes/Analysis_Tests.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/Example/Analysis.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/Analysis.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/Analysis.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/Analysis/AppDelegate.swift b/Example/Analysis/AppDelegate.swift index ac81159..64352d1 100644 --- a/Example/Analysis/AppDelegate.swift +++ b/Example/Analysis/AppDelegate.swift @@ -13,7 +13,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 { return true } } diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 0f5d591..a39a563 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Analysis (0.2.0) + - Analysis (0.3.0) DEPENDENCIES: - Analysis (from `../`) @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - Analysis: 00866c8642f25365be1797772e36f4277072f8f6 + Analysis: 556a6d4d9ddee23fb7c4bb5fd8f5c882b7958050 PODFILE CHECKSUM: 8aa19244f257b8174d0051e41788d104857daad3 -COCOAPODS: 1.1.1 +COCOAPODS: 1.4.0 diff --git a/Example/Tests/AnalysisTests.swift b/Example/Tests/AnalysisTests.swift index 6e7cec3..226a8a6 100644 --- a/Example/Tests/AnalysisTests.swift +++ b/Example/Tests/AnalysisTests.swift @@ -130,15 +130,15 @@ class AnalysisTests: XCTestCase { } func testWordFrequency() { - XCTAssertEqualWithAccuracy(three.frequency(of: "hello"), 33.3, accuracy: 0.1) - XCTAssertEqualWithAccuracy(three.frequency(of: "HELLO"), 33.3, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: "hello"), 33.3, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: "HELLO"), 33.3, accuracy: 0.1) XCTAssertEqual(three.frequency(of: "he"), 0.0) XCTAssertEqual(helloWorld1.frequency(of: "hello"), 50.0) XCTAssertEqual(repeating.frequency(of: "repeat"), 100.0) XCTAssertEqual(repeating.frequency(of: "Repeat"), 100.0) - XCTAssertEqualWithAccuracy(three.frequency(of: "Hello", caseSensitive: true), 33.3, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: "Hello", caseSensitive: true), 33.3, accuracy: 0.1) XCTAssertEqual(three.frequency(of: "hello", caseSensitive: true), 0.0) XCTAssertEqual(three.frequency(of: "he", caseSensitive: true), 0.0) @@ -149,17 +149,17 @@ class AnalysisTests: XCTestCase { } func testCharacterFrequency() { - XCTAssertEqualWithAccuracy(three.frequency(of: Character("h")), 16.6, accuracy: 0.1) - XCTAssertEqualWithAccuracy(three.frequency(of: Character("H")), 16.6, accuracy: 0.1) - XCTAssertEqualWithAccuracy(three.frequency(of: Character("i")), 5.5, accuracy: 0.1) - XCTAssertEqualWithAccuracy(helloWorld1.frequency(of: Character("h")), 7.7, accuracy: 0.1) - XCTAssertEqualWithAccuracy(repeating.frequency(of: Character("e")), 27.3, accuracy: 0.1) - XCTAssertEqualWithAccuracy(repeating.frequency(of: Character("E")), 27.3, accuracy: 0.1) - - XCTAssertEqualWithAccuracy(three.frequency(of: Character("H"), caseSensitive: true), 16.6, accuracy: 0.1) - XCTAssertEqualWithAccuracy(three.frequency(of: Character("i"), caseSensitive: true), 5.5, accuracy: 0.1) - XCTAssertEqualWithAccuracy(helloWorld1.frequency(of: Character("e"), caseSensitive: true), 7.7, accuracy: 0.1) - XCTAssertEqualWithAccuracy(repeating.frequency(of: Character("e"), caseSensitive: true), 27.3, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: Character("h")), 16.6, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: Character("H")), 16.6, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: Character("i")), 5.5, accuracy: 0.1) + XCTAssertEqual(helloWorld1.frequency(of: Character("h")), 7.7, accuracy: 0.1) + XCTAssertEqual(repeating.frequency(of: Character("e")), 27.3, accuracy: 0.1) + XCTAssertEqual(repeating.frequency(of: Character("E")), 27.3, accuracy: 0.1) + + XCTAssertEqual(three.frequency(of: Character("H"), caseSensitive: true), 16.6, accuracy: 0.1) + XCTAssertEqual(three.frequency(of: Character("i"), caseSensitive: true), 5.5, accuracy: 0.1) + XCTAssertEqual(helloWorld1.frequency(of: Character("e"), caseSensitive: true), 7.7, accuracy: 0.1) + XCTAssertEqual(repeating.frequency(of: Character("e"), caseSensitive: true), 27.3, accuracy: 0.1) XCTAssertEqual(three.frequency(of: Character("h"), caseSensitive: true), 0.0) XCTAssertEqual(three.frequency(of: Character("h"), caseSensitive: true), 0.0) @@ -167,21 +167,21 @@ class AnalysisTests: XCTestCase { } func testAverageCharactersPerWord() { - XCTAssertEqualWithAccuracy(three.averageCharacters(per: .word), 4.3, accuracy: 0.1) + XCTAssertEqual(three.averageCharacters(per: .word), 4.3, accuracy: 0.1) XCTAssertEqual(helloWorld1.averageCharacters(per: .word), 5.0) XCTAssertEqual(repeating.averageCharacters(per: .word), 6.0) } func testAverageCharactersPerSentence() { - XCTAssertEqualWithAccuracy(three.averageCharacters(per: .sentence), 5.3, accuracy: 0.1) + XCTAssertEqual(three.averageCharacters(per: .sentence), 5.3, accuracy: 0.1) XCTAssertEqual(helloWorld1.averageCharacters(per: .sentence), 13.0) XCTAssertEqual(repeating.averageCharacters(per: .sentence), 22.0) } func testAverageWordsPerSentence() { - XCTAssertEqualWithAccuracy(differentSentenceLengths.averageWordsPerSentence, 2.3, accuracy: 0.1) + XCTAssertEqual(differentSentenceLengths.averageWordsPerSentence, 2.3, accuracy: 0.1) XCTAssertEqual(three.averageWordsPerSentence, 1.0) XCTAssertEqual(helloWorld1.averageWordsPerSentence, 2.0) diff --git a/License b/License index d820407..1c8b2ef 100644 --- a/License +++ b/License @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Bas Broek +Copyright (c) 2018 Bas Broek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal