Chapter 19 Mediator Pattern

I’m lost as to what the colleague’s computed property does in the Mediator wrapper class. It says in your book that is “uses a filter to find colleagues from colleagueWrappers that have already been released and then returns an array of non-nil colleagues”

What has been released though? For reference, I mean this computer property:

public var colleagues: [ColleagueType] {
	var colleagues: [ColleagueType] = []
	colleagueWrappers = colleagueWrappers.filter {
		guard let colleague = $0.colleague else { return false }
		colleagues.append(colleague)
		return true
	}
	return colleagues
}

An explanation as to what the colleague wrapper class does would be really helpful too, it doesn’t really explain in the book what its purpose is.

@mcneils Thanks very much for your question!

A wrapper class is exactly that: It is more of a convenience class around ANOTHER type to provide simpler functionality, and hides complexity from the user. In this case, the computed property colleagues returns an array of type ColleagueType by iterating through the collection “colleagueWrappers”, and only including them in the array if they contain the property “colleague”.