The following code appears to silently shadow and preempt hidden private system API. This causes hard to detect and diagnose bugs when the new function uses different semantics than the original and the system code starts calling the extension, rather than the correct system function. From what I can tell, this is an encouraged design pattern, but it seems particularly fragile. Worse still, any future changes to the system base class introduce a whole new spin on the “fragile base class” problem when suddenly client code is extending and hiding a function that didn’t exist when the client code was written.
Is there something I’m missing here, or should be doing differently? One would hope access control or a namespace would prevent the extension of a function another module depends on, but that appears not to be true. The fact this happens silently is troubling, but the fact it seems possible after release to existing production code via a system software update seems far worse.
Thanks,
Nick
import HomeKit
extension HMHome
{
func roomWithUUID(inUUID:NSUUID) -> HMRoom?
{
for room in self.rooms {
if room.uniqueIdentifier == inUUID {
return room
}
}
return nil
}
}