简体   繁体   English

什么是Objective-C相当于一个空的Swift OptionSet?

[英]What is the Objective-C equivalent to an empty Swift OptionSet?

Please take a look at this simple Swift code: 请看一下这个简单的Swift代码:

UIView.animate(withDuration: duration, delay: interButtonDelay * Double(expanding ? index : index + 1), options: [], animations: {
            button.transform = expanding ? .init(scaleX: self.scale, y: self.scale) : .identity
            button.alpha = expanding ? 0.0 : 1.0
        }, completion: nil)

Here an empty array is passed into the options parameter. 这里将一个空数组传递给options参数。 I would like to find out what is the correct Objective-C equivalent to doing this. 我想找出与此相同的正确Objective-C是什么。 I assume it should be passing 0, but I want to be completely sure. 我认为它应该传递0,但我想完全确定。 Unfortunately the docs not telling anything regarding this. 不幸的是,文档没有说明这一点。

Swift's OptionSet was created to make bitmasks more pleasant to use. 创建Swift的OptionSet是为了使位掩码更加舒适。 In Swift, you spell the combined value as if it were a collection; 在Swift中,你将组合值拼写成一个集合; in Objective-C, it's an integral value, built with bitwise operators: 在Objective-C中,它是一个用位运算符构建的整数值:

NSUInteger options = UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseOut;

The Objective-C equivalent to an empty OptionSet is therefore indeed just 0. 因此,相当于空OptionSet的Objective-C实际上只是0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM