只需将这些样板代码
if ([self.delegate respondToSelector:@selector(photoController:didPhoto:)]) {
[self.delegate photoController:self didPhoto:photo];
}
替换为小巧的属性 `orNil
`,它在所有 `NSObject
` 子类上工作
[self.delegate.orNil photoController:self didPhoto:photo];
如果对象不响应选择器,则将 `nil
` 作为此选择器的目标使用 :)
orNil可通过CocoaPods访问。要安装它,只需将以下行添加到您的Podfile中
pod 'orNil'
Anton Bukov, [email protected]
orNil可在MIT许可证下获得。有关更多信息,请参阅LICENSE文件。