[swift-users] Checking/getting custom objects from a collection

Milos Rankovic milos at milos-and-slavica.net
Fri Apr 8 10:16:06 CDT 2016


My message bounced on account of size. I’m sorry if you receive multiple copies of this:

> “If Limb is a Component, then a Spider entity needs eight of them…”
That’s a fair question to ask. 

My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case of self-propelling creatures, you’d probably ask, “does it have legs”. On the other hand, asking, “does it (still) have a front left leg?” assumes that in general this entity has legs you can ask questions about. All of which would suggest that `SpiderLegs` component would be sufficient for most spider games…

As for the `add` and `remove` methods, I’d probably also return the removed component (if any):

	mutating func remove<T: Component>(_: T.Type) -> T? {
		return components.removeValueForKey(T.name) as? T
	}

milos
> On 8 Apr 2016, at 15:30, Adriano Ferreira <adriano.ferreira at me.com> wrote:
> 
> Hi Milos,
> 
> Thanks for getting back to me this quickly.
> 
> Well, this part specifically was more of a curiosity based on Jens’ comment:
> 
> “If Limb is a Component, then a Spider entity needs eight of them…”
> 
> I also confess I’m unsure about this… so please don’t bother then.
> 
> Looking forward to hearing your thoughts on the functions though.
> 
> Cheers,
> 
> — A

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160408/1b671416/attachment.html>


More information about the swift-users mailing list