SwiftyObjC
let a = @"hello"; //a is `NSString *const` now
a = @"world"; //produces error
var b = 5; //b is `const int` now
b = 10; //fine
iflet(c, [self getNullableString]) {
// c is not nil here
}
// c is not available here
ifletwhere(c, [self getNullableString], c.length > 5) {
// can have additional constraints
}
需求
Xcode 8
安装
SwiftyObjC通过CocoaPods提供。要安装它,只需将以下行添加到Podfile中
pod 'SwiftyObjC'
guard/guard let
它们是可能的,但没有实现,因为有两个显著的缺陷
- 我无法确保else块在编译时有返回/抛出。没有这个,我觉得太危险了
- 我无法确保有人写了
else
关键字,所以又有危险。
然而,我期待实现这些,所以如果你发现如何欺骗编译器,请提交一个笔记或PR。
许可证
SwiftyObjC 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。