ios - '++' 已弃用 : it will be removed in Swift 3

标签 ios swift swift2 swift3

<分区>

更新到 Xcode 7.3 后,我的项目中出现了一堆警告。

'++' is deprecated: it will be removed in Swift 3

有解决此警告的想法吗? ++-- 将来会被弃用的原因是什么?

最佳答案

从 Swift 2.2 开始,您应该改用 += 1-= 1

并且在查看了 Swift 的演进之后,有一些删除这些运算符的原因:

  1. These operators increase the burden to learn Swift as a first programming language - or any other case where you don't already know these operators from a different language.

  2. Their expressive advantage is minimal - x++ is not much shorter than x += 1.

  3. Swift already deviates from C in that the =, += and other assignment-like operations returns Void (for a number of reasons). These operators are inconsistent with that model.

  4. Swift has powerful features that eliminate many of the common reasons you'd use ++i in a C-style for loop in other languages, so these are relatively infrequently used in well-written Swift code. These features include the for-in loop, ranges, enumerate, map, etc.

  5. Code that actually uses the result value of these operators is often confusing and subtle to a reader/maintainer of code. They encourage "overly tricky" code which may be cute, but difficult to understand.

  6. While Swift has well defined order of evaluation, any code that depended on it (like foo(++a, a++)) would be undesirable even if it was well-defined.

  7. These operators are applicable to relatively few types: integer and floating point scalars, and iterator-like concepts. They do not apply to complex numbers, matrices, etc.

Finally, these fail the metric of "if we didn't already have these, would we add them to Swift 3?"

请查看Swift evolution了解更多信息。

关于ios - '++' 已弃用 : it will be removed in Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36173096/

相关文章:

ios - 将 UIImagePickerController 修复为纵向

ios - Spritekit 子类节点显示为 nil

ios - MKMapViewDelegate map View :didUpdateUserLocation: method not called on iOS5

swift - 触摸结束时如何更改 UISlider Thumb 外观

swift - Flutter Google Maps iOS构建失败

swift - 'Constant captured by a closure before being initialized'错误是什么原因造成的

ios - iOS 中的 EFCircularSlider

swift - 如何在调用 `viewDidLoad` 之前加载 self.navigationController

ios - UIActivityViewController WhatsApp 返回聊天按钮不起作用

ios - 如何在 Swift 中发布请求