xcode 无法快速使用“分析”吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29326036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:53:15  来源:igfitidea点击:

Is it not possible to use "Analyze" with swift?

xcodeswiftxcode6

提问by Kaizer Sozay

Previously with objective-c code, I could "Analyze" - CMD + Shift + B and Xcode would warn me of all kinds of wrongdoings on my part.

以前使用 Objective-c 代码,我可以“分析”——CMD + Shift + B 和 Xcode 会警告我我的各种错误行为。

It seems that with Swift, I can do no wrong! No warnings of any kind! But clearly there is a memory leak in my code.

似乎有了 Swift,我就不会错了!没有任何警告!但显然我的代码中存在内存泄漏。

Is there some setting I have to enable to get Swift to analyze my code properly? (I am aware I should use the profiler and test on an actual device, which I do, but I wonder why "Analyze" doesn't do anything.

是否需要启用某些设置才能让 Swift 正确分析我的代码?(我知道我应该使用分析器并在实际设备上进行测试,我这样做了,但我想知道为什么“分析”不做任何事情。

采纳答案by ?afak Gezer

Unfortunately no. Even many releases later, the latest version of XCode (6.4) still cannot do Swift analysis. The 'Analyze' option only works for the Objective C files in your project.

抱歉不行。即使后来发布了很多版本,最新版本的 XCode(6.4)仍然无法进行 Swift 分析。“分析”选项仅适用于项目中的目标 C 文件。

Let's hope the next version will have it, along with the refactoring capabilities which also are still limited to Objective C code.

让我们希望下一个版本能够拥有它,以及仍然仅限于 Objective C 代码的重构功能。

回答by Motti Shneor

To this moment (Xcode 8.3.x) Static Code analysis skips Swift code. Some Swift warnings cover some of the issues previously detected by the analyzer.

到目前为止 (Xcode 8.3.x) 静态代码分析跳过了 Swift 代码。一些 Swift 警告涵盖了分析器之前检测到的一些问题。

Also the upcoming Xcode 9 (presented in WWDC 2017) does not announce any change in this direction.

此外,即将推出的 Xcode 9(在 WWDC 2017 中展示)也没有宣布在这个方向上有任何变化。

Many issues detected by the static Analyzer of Obj-C are for the most part preventedby the actual Swift language (e.g. unintended fall-through in switch statements). Other issues and scenarios formerly caught by the analyser, are now caught directly by the Swift compiler.

Obj-C 的静态分析器检测到的许多问题在很大程度上是由实际的 Swift 语言阻止的(例如,switch 语句中的意外失败)。以前由分析器捕获的其他问题和场景现在由 Swift 编译器直接捕获。

Many flows and scenarios leading to program crash - (e.g. accessing null pointers, leaving dangling pointers, or accessing released memory blocks) are hardly possible in Swift. Swift strong typing, heavy use of optionals, the requirement to completely cover protocols, and switch-case over enums, etc. remove another bunch of issues previously found by the analyzer.

许多导致程序崩溃的流程和场景——(例如访问空指针、留下悬空指针或访问已释放的内存块)在 Swift 中几乎是不可能的。Swift 强类型、大量使用可选项、完全覆盖协议的要求以及在枚举上切换大小写等,消除了分析器之前发现的另一堆问题。

A Swift static code analyzer will need to go to another level in analyzing program logic, which is much harder, and theoretically impossible to do completely.

Swift 静态代码分析器在分析程序逻辑方面需要更上一层楼,这要困难得多,而且理论上不可能完全做到。

So - although I'm quite thrilled to think of some future Xcode Analyzer, I wouldn't hold my breath waiting for it

所以 - 虽然我很高兴想到一些未来的 Xcode Analyzer,但我不会屏住呼吸等待它

回答by Dariusz Wiechecki

Update:

更新:

As more and more people are down voting my post, just small update from my side. It seems that indeed apple just did allow for pressing option "Analyze" but in the background it does nothing (state for 2016.04.21, though I am not working on iOS for the moment and probably I don't have the latest version of Xcode).

随着越来越多的人对我的帖子投反对票,我这边只是一个小小的更新。似乎苹果确实允许按下选项“分析”,但在后台它什么都不做(状态为 2016.04.21,虽然我目前不在 iOS 上工作,可能我没有最新版本的 Xcode )。

below my original post:

在我原来的帖子下面:



Just for next readers of this article. At this moment Xcode 7 is already able to analyze also Swift projects. Refactoring is still not working though.

仅供本文的下一位读者使用。此时 Xcode 7 已经能够分析 Swift 项目。重构仍然不起作用。

BR, Darek

BR,达瑞克