Skip to content

Commit

Permalink
Tolerate more shapes of SourceKit output with Swift 6 (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh authored Oct 18, 2024
1 parent 2610c2d commit 3db8072
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## Main

#### Breaking

* None.

#### Enhancements

* Build without warnings with Swift 6 compiler.
[SimplyDanny](https://github.com/SimplyDanny)

* Generate docs cleanly with Swift 6 compiler.
[John Fairhurst](https://github.com/johnfairh)
[#821]((https://github.com/realm/SourceKitten/issues/821)

#### Bug Fixes

* None.

## 0.36.0

##### Breaking
Expand Down
20 changes: 10 additions & 10 deletions Source/SourceKittenFramework/JSONOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ public func toJSON(_ object: Any, options: JSONSerialization.WritingOptions? = n
- returns: JSON-serializable value.
*/
public func toNSDictionary(_ dictionary: [String: SourceKitRepresentable]) -> NSDictionary {
var anyDictionary = [String: Any]()
for (key, object) in dictionary {
func toNSDictionaryValue(_ object: SourceKitRepresentable) -> Any {
switch object {
case let object as [SourceKitRepresentable]:
anyDictionary[key] = object.map { toNSDictionary($0 as! [String: SourceKitRepresentable]) }
return object.map { toNSDictionaryValue($0) }
case let object as [[String: SourceKitRepresentable]]:
anyDictionary[key] = object.map { toNSDictionary($0) }
return object.map { toNSDictionary($0) }
case let object as [String: SourceKitRepresentable]:
anyDictionary[key] = toNSDictionary(object)
return toNSDictionary(object)
case let object as String:
anyDictionary[key] = object
return object
case let object as Int64:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Bool:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Any:
anyDictionary[key] = object
return object
default:
fatalError("Should never happen because we've checked all SourceKitRepresentable types")
}
}
return anyDictionary.bridge()

return dictionary.mapValues(toNSDictionaryValue).bridge()
}

#if !os(Linux)
Expand Down

0 comments on commit 3db8072

Please sign in to comment.