Swift2.0后 "|" cannot be applied to two operands 问题解决办法

Blog UV: AmazingCounters.com

直接看代码:

UIView.transitionFromView(graphView, toView:counterView, duration: 0.5, options: UIViewAnimationOptions.ShowHideTransitionViews | UIViewAnimationOptions.TransitionFlipFromRight, completion:nil)  

今天要写个控件动画的时候写在这句,突然发现编译器报错Binary operator “|” cannot be applied to two operands,也就是说不能再用"|"符号来为option这个参数应用两个value了,不用慌,翻了翻资料听说swift这次改版后建议使用OptionSetType,OK,直接了当改成如下:

UIView.transitionFromView(counterView, toView:graphView, duration: 0.5, options:UIViewAnimationOptions.ShowHideTransitionViews.union(UIViewAnimationOptions.TransitionFlipFromRight), completion: nil)  

使用union应用两个value毫无违和感。

到这里突然又想到以前见过别人这样写消息推送:

UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: nil))  

ok,我看见了数组,做了下测试:

UIView.transitionFromView(graphView, toView:counterView, duration: 0.5, options: [UIViewAnimationOptions.ShowHideTransitionViews,UIViewAnimationOptions.TransitionFlipFromRight], completion:nil)  

成功通过编译并且完美实现,这种写法能应对传入多个value并且非常有格式性

comments powered by Disqus