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:

enter image description here


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -