Skip to content

Commit

Permalink
Prefer non-optional UTF8 String <-> Data conversion.
Browse files Browse the repository at this point in the history
Hopefully addresses the swift-lint errors.

Fix via realm/SwiftLint#5263
  • Loading branch information
mhammond authored and linabutler committed May 30, 2024
1 parent 3ca0676 commit 8beb7ef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions components/nimbus/ios/Nimbus/Dictionary+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import Foundation
extension Dictionary where Key == String, Value == Any {
func stringify() throws -> String {
let data = try JSONSerialization.data(withJSONObject: self)
guard let s = String(data: data, encoding: .utf8) else {
throw NimbusError.JsonError(message: "Unable to encode")
}
return s
return String(decoding: data, as: UTF8.self)
}

static func parse(jsonString string: String) throws -> [String: Any] {
Expand Down
2 changes: 1 addition & 1 deletion components/nimbus/ios/Nimbus/Nimbus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ extension Nimbus: NimbusMessagingProtocol {
encoder.keyEncodingStrategy = .convertToSnakeCase

let data = try encoder.encode(additionalContext)
let string = String(data: data, encoding: .utf8)!
let string = String(decoding: data, as: UTF8.self)
return try createMessageHelper(string: string)
}

Expand Down

0 comments on commit 8beb7ef

Please sign in to comment.