Skip to content

Commit 830ed6a

Browse files
NicolasCombe5555Nicolas Combe
andauthored
Refactor FXIOS-10468 [SwiftLint] Fix force_unwrapping in /Widgets and /OpenInFocus (#29669)
* Refactor FXIOS-10468 [SwiftLint] Fix force_unwrapping in /Widgets * Refactor FXIOS-10468 [SwiftLint] Fix force_unwrapping in /OpenInFocus --------- Co-authored-by: Nicolas Combe <[email protected]>
1 parent 716e1de commit 830ed6a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Dangerfile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func checkDescriptionSection() {
432432

433433
func commentDescriptionSection(desc: String) {
434434
let count = desc.trimmingCharacters(in: .whitespacesAndNewlines).count
435-
if count == 0 {
435+
if count == 0 { // swiftlint:disable:this empty_count
436436
fail("""
437437
Details needed! Your description section is empty. Adding a bit more context will make reviews smoother.
438438
""")

focus-ios/OpenInFocus/ActionViewController.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ extension NSItemProvider {
3333
}
3434
}
3535

36-
class ActionViewController: SLComposeServiceViewController {
37-
private var isKlar: Bool { return (Bundle.main.infoDictionary!["CFBundleIdentifier"] as! String).contains("Klar") }
36+
final class ActionViewController: SLComposeServiceViewController {
37+
private var isKlar: Bool {
38+
guard let string = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String else { return false }
39+
return string.contains("Klar")
40+
}
3841
private var urlScheme: String { return isKlar ? "firefox-klar" : "firefox-focus" }
3942

4043
override func isContentValid() -> Bool { return true }
@@ -97,21 +100,21 @@ class ActionViewController: SLComposeServiceViewController {
97100
}
98101

99102
private func handleUrl(_ url: NSURL) {
100-
// From http://stackoverflow.com/questions/24297273/openurl-not-work-in-action-extension
103+
// From https://stackoverflow.com/questions/24297273/openurl-not-work-in-action-extension
101104
var responder = self as UIResponder?
102105
let selectorOpenURL = sel_registerName("openURL:")
103-
while responder != nil {
106+
while let currentResponder = responder {
104107
if #available(iOS 18.0, *) {
105108
if let application = responder as? UIApplication {
106109
application.open(url as URL, options: [:], completionHandler: nil)
107110
}
108111
} else {
109-
if responder!.responds(to: selectorOpenURL) {
110-
responder!.callSelector(selector: selectorOpenURL, object: url, delay: 0)
112+
if currentResponder.responds(to: selectorOpenURL) {
113+
currentResponder.callSelector(selector: selectorOpenURL, object: url, delay: 0)
111114
}
112115
}
113116

114-
responder = responder!.next
117+
responder = currentResponder.next
115118
}
116119
finish()
117120
}

focus-ios/Widgets/Widgets.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ struct FocusWidgets_Previews: PreviewProvider {
6363

6464
fileprivate extension String {
6565
static var appNameForBundle: String {
66-
var isKlar: Bool { return (Bundle.main.infoDictionary!["CFBundleIdentifier"] as! String).contains("Klar") }
66+
var isKlar: Bool {
67+
guard let string = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String else { return false }
68+
return string.contains("Klar")
69+
}
6770
return isKlar ? "Klar" : "Focus"
6871
}
6972
// Quick Action - Small Size - Gallery View
@@ -100,7 +103,7 @@ fileprivate extension Bool {
100103
}
101104

102105
fileprivate extension URL {
103-
static let deepLinkURL = URL(string: "firefox-focus://widget")!
106+
static let deepLinkURL = URL(string: "firefox-focus://widget")
104107
}
105108

106109
fileprivate extension View {

0 commit comments

Comments
 (0)