Skip to content

Commit

Permalink
Remove superfluous force cast. (#56)
Browse files Browse the repository at this point in the history
Just another small refactoring. The forced cast is safe and can never
crash, but somehow I like to avoid them whenever possible. Please feel
free to close.
  • Loading branch information
Lukas-Stuehrk authored Jun 13, 2024
1 parent b53f822 commit 8c4b880
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/STTextView/STTextView+NSTextInputClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ extension STTextView: NSTextInputClient {
@objc public func setMarkedText(_ string: Any, selectedRange: NSRange, replacementRange: NSRange) {
let attributedMarkedString: NSAttributedString
switch string {
case is NSAttributedString:
let attributedString = NSMutableAttributedString(attributedString: string as! NSAttributedString)
case let attributedString as NSAttributedString:
let attributedString = NSMutableAttributedString(attributedString: attributedString)

// it comes with unexpected NSUnderlineColorAttributeName with a clear color that makes it not visible
// probably it should be more sophisticated to care about the clear underline and do something about
Expand All @@ -50,9 +50,9 @@ extension STTextView: NSTextInputClient {
let attrs = typingAttributes.merging(markedTextAttributes) { (_, new) in new }
attributedString.addAttributes(attrs, range: NSRange(location: 0, length: attributedString.length))
attributedMarkedString = attributedString
case is String:
case let string as String:
let attrs = typingAttributes.merging(markedTextAttributes) { (_, new) in new }
attributedMarkedString = NSAttributedString(string: string as! String, attributes: attrs)
attributedMarkedString = NSAttributedString(string: string, attributes: attrs)
default:
assertionFailure()
return
Expand Down

0 comments on commit 8c4b880

Please sign in to comment.