Skip to content

Commit b1afbaf

Browse files
authored
Swift 5.1 (#22)
* Use single-quote strings in podspec * Update Podfile * Update example project * Update library * Add changelog entry
1 parent 31ddfcb commit b1afbaf

6 files changed

Lines changed: 65 additions & 36 deletions

File tree

Analysis.podspec

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
Pod::Spec.new do |s|
2-
s.name = "Analysis"
3-
s.version = "0.4.0"
4-
s.summary = "Analyse your strings."
2+
s.name = 'Analysis'
3+
s.version = '0.5.0'
4+
s.summary = 'Analyse your strings.'
55

66
s.description = <<-DESC
77
Analysis analyses strings, checking word count, sentence count, frequency of words and more.
88
DESC
99

10-
s.homepage = "https://github.com/BasThomas/Analysis"
11-
s.license = { :type => "MIT", :file => "LICENSE" }
12-
s.author = { "Bas Broek" => "bas@basbroek.nl" }
13-
s.source = { :git => "https://github.com/BasThomas/Analysis.git", :tag => s.version }
14-
s.social_media_url = "https://twitter.com/basthomas"
10+
s.homepage = 'https://github.com/BasThomas/Analysis'
11+
s.license = { :type => 'MIT', :file => 'LICENSE' }
12+
s.author = { 'Bas Broek' => 'bas@basbroek.nl' }
13+
s.source = { :git => 'https://github.com/BasThomas/Analysis.git', :tag => s.version }
14+
s.social_media_url = 'https://twitter.com/basthomas'
1515

16-
s.ios.deployment_target = "8.0"
17-
s.swift_version = "5.0"
16+
s.ios.deployment_target = '8.0'
17+
s.swift_version = '5.1'
1818

19-
s.source_files = "Analysis/Classes/**/*"
19+
s.source_files = 'Analysis/Classes/**/*'
2020

21-
s.frameworks = "Foundation"
21+
s.frameworks = 'Foundation'
2222
end

Analysis/Classes/Analysis.swift

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public struct Analysis: Hashable {
3434
sentences = input
3535
.replacingOccurrences(of: "! ", with: "!\n")
3636
.replacingOccurrences(of: ". ", with: ".\n")
37-
.replacingOccurrences(of: "? ", with: "?\n").lines
37+
.replacingOccurrences(of: "? ", with: "?\n")
38+
.lines
3839
.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
3940
words = input
4041
.split(separator: " ")
@@ -44,7 +45,7 @@ public struct Analysis: Hashable {
4445

4546
/// Returns the sentence count of the `input`.
4647
public func sentenceCount() -> Int {
47-
return sentences.count
48+
sentences.count
4849
}
4950

5051
/// Returns the word count of the `input`.
@@ -62,7 +63,7 @@ public struct Analysis: Hashable {
6263

6364
/// Returns the total amount of syllables of the `input`.
6465
public func syllableCount() -> Int {
65-
return words
66+
words
6667
.map { $0.syllables }
6768
.reduce(0, +)
6869
}
@@ -105,7 +106,7 @@ public struct Analysis: Hashable {
105106
/// - Returns: A `Dictionary` containing the words and their
106107
/// occurence.
107108
public func wordOccurrences(caseSensitive: Bool = false) -> [String: Int] {
108-
return _wordOccurrences(caseSensitive: caseSensitive)
109+
_wordOccurrences(caseSensitive: caseSensitive)
109110
}
110111

111112
/// Returns the character occurrences of the `input`.
@@ -117,7 +118,7 @@ public struct Analysis: Hashable {
117118
/// - Returns: A `Dictionary` containing the characters and their
118119
/// occurence.
119120
public func characterOccurences(caseSensitive: Bool = false) -> [Character: Int] {
120-
return _characterOccurences(caseSensitive: caseSensitive)
121+
_characterOccurences(caseSensitive: caseSensitive)
121122
}
122123

123124
/// Returns the amount of occurrences of the specified word.
@@ -169,7 +170,10 @@ public struct Analysis: Hashable {
169170
of word: String,
170171
caseSensitive: Bool = false
171172
) -> Percentage {
172-
return Double(occurrences(of: word, caseSensitive: caseSensitive)) / Double(wordCount()) * 100.0
173+
Double(occurrences(
174+
of: word,
175+
caseSensitive: caseSensitive
176+
)) / Double(wordCount()) * 100.0
173177
}
174178

175179
/// Returns the frequency of the specified `Character`.
@@ -187,7 +191,12 @@ public struct Analysis: Hashable {
187191
caseSensitive: Bool = false,
188192
includingSpaces: Bool = true
189193
) -> Percentage {
190-
return Double(occurrences(of: character, caseSensitive: caseSensitive)) / Double(characterCount(includingSpaces: includingSpaces)) * 100.0
194+
Double(occurrences(
195+
of: character,
196+
caseSensitive: caseSensitive
197+
)) / Double(characterCount(
198+
includingSpaces: includingSpaces
199+
)) * 100.0
191200
}
192201

193202
/// Returns the average characters of the specified `LengthOption`.
@@ -209,49 +218,49 @@ public struct Analysis: Hashable {
209218

210219
/// Returns the average words per sentence.
211220
public var averageWordsPerSentence: Double {
212-
return Double(wordCount()) / Double(sentenceCount())
221+
Double(wordCount()) / Double(sentenceCount())
213222
}
214223

215224
private var _wordsPerSentences: Double {
216-
return Double(wordCount()) / Double(sentenceCount())
225+
Double(wordCount()) / Double(sentenceCount())
217226
}
218227

219228
private var _syllablesPerWords: Double {
220-
return Double(syllableCount()) / Double(wordCount())
229+
Double(syllableCount()) / Double(wordCount())
221230
}
222231

223232
/// Returns the Flesch reading ease score.
224233
///
225234
/// - Note: https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease
226235
public func fleschReadingEase() -> Percentage {
227-
return 206.835 - 1.015 * _wordsPerSentences - 84.6 * _syllablesPerWords
236+
206.835 - 1.015 * _wordsPerSentences - 84.6 * _syllablesPerWords
228237
}
229238

230239
/// Returns the Flesch-Kincaid grade level.
231240
///
232241
/// - Note: https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch.E2.80.93Kincaid_grade_level
233242
public func fleschKincaidGradeLevel() -> Grade {
234-
return 0.39 * _wordsPerSentences + 11.8 * _syllablesPerWords - 15.59
243+
0.39 * _wordsPerSentences + 11.8 * _syllablesPerWords - 15.59
235244
}
236245
}
237246

238247
extension Analysis: Comparable {
239248

240249
public static func <(lhs: Analysis, rhs: Analysis) -> Bool {
241-
return lhs.input < rhs.input
250+
lhs.input < rhs.input
242251
}
243252
}
244253

245254
extension Analysis: CustomStringConvertible, CustomDebugStringConvertible {
246255

247256
/// A textual representation of this instance.
248257
public var description: String {
249-
return "Analysis(\"\(input)\")"
258+
"Analysis(\"\(input)\")"
250259
}
251260

252261
/// A representation of the string that is suitable for debugging.
253262
public var debugDescription: String {
254-
return dump(description)
263+
dump(description)
255264
}
256265
}
257266

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# next
22

3+
# [0.5.0](https://github.com/BasThomas/Analysis/releases/tag/0.4.0)
4+
5+
- Updated to Swift 5.1.
6+
37
# [0.4.0](https://github.com/BasThomas/Analysis/releases/tag/0.4.0)
48

59
- **Breaking**: Nested `LengthOption` under the `Analysis` namespace. If it is accessed without type inference,

Example/Analysis/AppDelegate.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17-
return true
16+
func application(
17+
_ application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
19+
) -> Bool {
20+
true
1821
}
1922
}

Example/Analysis/UIViewController+Safari.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,30 @@ import SafariServices
1111

1212
extension UIViewController: SFSafariViewControllerDelegate {
1313

14-
func open(url: URL, inSafariViewController safariViewController: Bool = true, reader: Bool = false) {
15-
if !safariViewController {
14+
func open(
15+
url: URL,
16+
inSafariViewController safariViewController: Bool = true,
17+
reader: Bool = false,
18+
application: UIApplication = .shared
19+
) {
20+
func openSafari(with url: URL) {
1621
if #available(iOS 10.0, *) {
17-
UIApplication.shared.open(url)
22+
application.open(url)
1823
} else {
19-
UIApplication.shared.openURL(url)
24+
application.openURL(url)
2025
}
26+
}
27+
if safariViewController == false {
28+
openSafari(with: url)
2129
} else if #available(iOS 9.0, *) {
22-
let safariViewController = SFSafariViewController(url: url, entersReaderIfAvailable: reader)
30+
let safariViewController = SFSafariViewController(
31+
url: url,
32+
entersReaderIfAvailable: reader
33+
)
2334
safariViewController.delegate = self
2435
present(safariViewController, animated: true)
36+
} else {
37+
openSafari(with: url)
2538
}
2639
}
2740

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- Analysis (0.4.0)
2+
- Analysis (0.5.0)
33

44
DEPENDENCIES:
55
- Analysis (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
Analysis: faa09d680f722f4111f2f4dc69492cfc228f0ee4
12+
Analysis: 7198ca0acc133fe99510f82fe241e65b77de2fbb
1313

1414
PODFILE CHECKSUM: d91e06da3cd073207837737c6c65ef37d1dfd49f
1515

0 commit comments

Comments
 (0)