Skip to content

Commit

Permalink
⭐️ Impl: RNIDictionarySynthesizable
Browse files Browse the repository at this point in the history
Related:
* TODO:2023-03-04-06-34-28 - Library Native Cleanup
  • Loading branch information
dominicstop committed Mar 26, 2023
1 parent e4efc11 commit 1165dcb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ios/src_library/Helpers+Utilities/RNIDictionarySynthesizable.swift
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 }
);
};
};

0 comments on commit 1165dcb

Please sign in to comment.