【发布时间】:2015-02-14 12:05:20
【问题描述】:
我不明白为什么 & 和 在 Swift 中不起作用。请帮我将 Objective-c 代码示例翻译成 Swift。
示例 1
UIViewController *viewController = [[UIViewController alloc] init];
viewController.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeTop;
if (viewController.edgesForExtendedLayout & UIRectEdgeBottom) {
NSLog(@"got it!");
}
我正在尝试用 Swift 翻译它,但出错了
let viewController = UIViewController()
viewController.edgesForExtendedLayout = .Bottom | .Top
if viewController.edgesForExtendedLayout & .Bottom {
println("got it!")
}
示例 2
typedef NS_OPTIONS(NSInteger, kViewControllerAnchoredGesture) {
kViewControllerAnchoredGestureNone = 0,
kViewControllerAnchoredGesturePanning = 1 << 0,
kViewControllerAnchoredGestureTapping = 1 << 1,
kViewControllerAnchoredGestureCustom = 1 << 2,
kViewControllerAnchoredGestureDisabled = 1 << 3
};
这里我不明白为什么无法编译,我该如何解决?
enum kViewControllerAnchoredGesture: NSInteger {
case None = 0
case Panning = 1 << 0
case Tapping = 1 << 1
case Custom = 1 << 2
case Disabled = 1 << 3
}
提前致谢!
【问题讨论】:
-
您也可以尝试设置正确的值而不进行位移。 IE。 0、1、2、4、8、16
标签: objective-c swift enums translate