什么是Objective

系统教程 行业动态 更新时间:2024-06-14 16:58:00
什么是Objective-C相当于一个空的Swift OptionSet?(What is the Objective-C equivalent to an empty Swift OptionSet?)

请看一下这个简单的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)

这里将一个空数组传递给options参数。 我想找出与此相同的正确Objective-C是什么。 我认为应该传递0,但我想完全确定。 不幸的是,文档没有说明这一点。

Please take a look at this simple Swift code:

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. I would like to find out what is the correct Objective-C equivalent to doing this. I assume it should be passing 0, but I want to be completely sure. Unfortunately the docs not telling anything regarding this.

最满意答案

创建Swift的OptionSet是为了使位掩码更加舒适。 在Swift中,你将组合值拼写成一个集合; 在Objective-C中,它是一个用位运算符构建的整数值:

NSUInteger options = UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseOut;

因此,相当于空OptionSet的Objective-C实际上只是0。

Swift's OptionSet was created to make bitmasks more pleasant to use. In Swift, you spell the combined value as if it were a collection; in Objective-C, it's an integral value, built with bitwise operators:

NSUInteger options = UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseOut;

The Objective-C equivalent to an empty OptionSet is therefore indeed just 0.

更多推荐

本文发布于:2023-04-14 05:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/db637cc1d7cab0772c52755c815b3653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Objective

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!