-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related: * TODO:2023-03-04-06-34-28 - Library Native Cleanup
- Loading branch information
1 parent
e4efc11
commit 1165dcb
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
ios/src_library/Helpers+Utilities/RNIDictionarySynthesizable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// RNIDictionarySynthesizable.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 3/26/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol RNIDictionarySynthesizable { | ||
var synthesizedDictionary: Dictionary<String, Any> { get }; | ||
}; | ||
|
||
extension RNIDictionarySynthesizable { | ||
public var synthesizedDictionary: Dictionary<String, Any> { | ||
let mirror = Mirror(reflecting: self); | ||
let properties = mirror.children; | ||
|
||
let propertyValueMap = properties.lazy.map { ( | ||
property: String?, value: Any) -> (String, Any)? in | ||
|
||
guard let property = property else { return nil } | ||
return (property, value) | ||
}; | ||
|
||
return Dictionary( | ||
uniqueKeysWithValues: propertyValueMap.compactMap { $0 } | ||
); | ||
}; | ||
}; |