Anonymous Anonymous - 6 months ago
612 0

No description

Swift

metatype_loop_question

func encode(to encoder: Encoder) throws { 
   var container = encoder.container(keyedBy: CodingKeys.self)

   var arrs = [String: [AnyClass]]()

   for stype in [A, B] {
      arrs[NSStringFromClass(stype)] = [stype]()
   }

  for event in self.events {
      for stype in [A,B] {
         if event is stype {
            arrs[NSStringFromClass(stype)]!.append(event as! stype)
         }
   }
   
   for  arr in arrs {
      try encoder.encode(arr, forKey: //some arbitrary key)
   }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download