ios - Generic toArray<T> function which can call an init on the Type T -
i have struct called flowercategory shown below:
struct flowercategory { var id :int? var title :string var imageurl :string } extension flowercategory { init?(node :node) { // here } }
i creating extension on node class convert node typed class array. problem cannot invoke t.init initializer shown below:
extension node { func toarray<t>() -> [t]? { guard let nodes = self.nodearray else { return nil } return nodes.flatmap(t.init) // not work } }
is there anyway trying achieve?
update:
Comments
Post a Comment