mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-23 19:36:26 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
34 lines
1.2 KiB
Swift
34 lines
1.2 KiB
Swift
extension Dictionary where Key == String, Value == Any? {
|
|
func removingEmptyArraysDictionariesAndNils() -> [String: Any] {
|
|
var new: [String: Any] = [:]
|
|
filter(outNil).forEach { pair in
|
|
let value: Any
|
|
if let array = pair.value as? [[String: Any?]] {
|
|
value = array.removingEmptyArraysDictionariesAndNils()
|
|
} else if let dictionary = pair.value as? [String: Any?] {
|
|
value = dictionary.removingEmptyArraysDictionariesAndNils()
|
|
} else {
|
|
value = pair.value! // nil is filtered out :)
|
|
}
|
|
new[pair.key] = value
|
|
}
|
|
return new
|
|
.filter(outEmptyArrays)
|
|
.filter(outEmptyDictionaries)
|
|
}
|
|
|
|
func outEmptyArrays(_ pair: (key: String, value: Any)) -> Bool {
|
|
guard let array = pair.value as? [Any] else { return true }
|
|
return !array.isEmpty
|
|
}
|
|
|
|
func outEmptyDictionaries(_ pair: (key: String, value: Any)) -> Bool {
|
|
guard let dictionary = pair.value as? [String: Any] else { return true }
|
|
return !dictionary.isEmpty
|
|
}
|
|
|
|
func outNil(_ pair: (key: String, value: Any?)) -> Bool {
|
|
return pair.value != nil
|
|
}
|
|
}
|