Skip to content

Commit

Permalink
Fix optional wrapping issue in mapToStrings function by explicitly… (#24
Browse files Browse the repository at this point in the history
)

Fix optional wrapping issue in mapToStrings function by explicitedly allowing Any? values then unwrapping them.
  • Loading branch information
didiergarcia committed Jan 17, 2024
1 parent fd06a43 commit f06278b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Sources/SegmentFirebase/FirebaseDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,19 @@ extension FirebaseDestination {
}

// Makes sure all traits are string based for Firebase API
func mapToStrings(_ mapDictionary: [String: Any], finalize: (String, String) -> Void) {
func mapToStrings(_ mapDictionary: [String: Any?], finalize: (String, String) -> Void) {

for (key, data) in mapDictionary {
var dataString = data as? String ?? "\(data)"
let keyString = key.replacingOccurrences(of: " ", with: "_")
dataString = dataString.trimmingCharacters(in: .whitespacesAndNewlines)
finalize(keyString, dataString)

// Since dictionary values can be Optional we have to unwrap them
// before encoding so that we don't encode them as "Optional(*)"
// Note: nil values are NOT encoded.
if let d = data {
var dataString = d as? String ?? "\(d)"
let keyString = key.replacingOccurrences(of: " ", with: "_")
dataString = dataString.trimmingCharacters(in: .whitespacesAndNewlines)
finalize(keyString, dataString)
}
}
}
}
Expand Down

0 comments on commit f06278b

Please sign in to comment.