一个简化...
建筑物有一系列公寓对象。每个公寓都有一个 currentTenant。这些租户属于 Person 类型。请注意,currentTenant 没有对公寓的引用,因此无法将信息发送回链。
当租户遇到管道问题时,他会提出 NSNotification:
[nc postNotificationName:@"PlumbingIssue" object:self];
每个公寓仅观察其当前租户的通知(这是在公寓建造时设置的,在当前租户之前):
[nc addObserver:self selector:@selector(alertBuildingManager:) name:@"PlumbingIssue" object:[self currentTenant];
当公寓收到来自它自己的 currentTenant 的通知时,它会发送它自己的通知“PlumberRequired”,以及 NSDictionary 中的公寓编号和 currentTenant。
Apartment 观察这些通知,它将从任何公寓(或其他对象)获取:
[nc addObserver:self selector:@selector(callPlumber) name:@"PlumberRequired" object:nil];
这里有什么我可能会从根本上出错的地方吗?正在发生的事情是公寓正在接收来自任何和所有当前租户的通知,而不仅仅是它自己的。
抱歉,实际代码有点太笨拙,无法发布。只是想知道我对观察来自特定发件人的通知的理解是否存在差距?