[swift-users] Checking/getting custom objects from a collection
Jens Alfke
jens at mooseyard.com
Thu Apr 7 19:29:03 CDT 2016
I’m not familiar with this design pattern, but it looks like Entity would just contain an array of Component. That makes add() and remove() straightforward.
I’m not sure about your get() method. It sounds as though the implication is that an entity could only contain a single component of a given class, but that sounds awfully limiting. (If Limb is a Component, then a Spider entity needs eight of them…) I also don’t believe that Swift is dynamic enough to be able to interrogate the classes of components that way at runtime. You could implement that at a higher level by adding a `type` property to ComponentType, that returns some component-type enumeration or maybe a string, and checking component types via that property.
—Jens
More information about the swift-users
mailing list