Skip to content

Commit 9d59125

Browse files
committed
Remove force unwrap
1 parent 6e5fd5c commit 9d59125

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

EditorExtension/Helpers.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,20 @@ extension EditorContent {
4343
let buffer = invocation.buffer
4444
self.init(
4545
content: buffer.completeBuffer,
46-
lines: buffer.lines as! [String],
46+
lines: buffer.lines as? [String] ?? [],
4747
uti: buffer.contentUTI,
4848
cursorPosition: ((buffer.selections.lastObject as? XCSourceTextRange)?.end).map {
4949
CursorPosition(line: $0.line, character: $0.column)
5050
} ?? CursorPosition(line: 0, character: 0),
5151
selections: buffer.selections.map {
52-
Selection(
53-
start: CursorPosition(
54-
line: ($0 as! XCSourceTextRange).start.line,
55-
character: ($0 as! XCSourceTextRange).start.column
56-
),
57-
end: CursorPosition(
58-
line: ($0 as! XCSourceTextRange).end.line,
59-
character: ($0 as! XCSourceTextRange).end.column
60-
)
52+
let sl = ($0 as? XCSourceTextRange)?.start.line ?? 0
53+
let sc = ($0 as? XCSourceTextRange)?.start.column ?? 0
54+
let el = ($0 as? XCSourceTextRange)?.end.line ?? 0
55+
let ec = ($0 as? XCSourceTextRange)?.end.column ?? 0
56+
57+
return Selection(
58+
start: CursorPosition( line: sl, character: sc ),
59+
end: CursorPosition( line: el, character: ec )
6160
)
6261
},
6362
tabSize: buffer.tabWidth,

0 commit comments

Comments
 (0)