美文网首页shmily-iOS/Mac
Xcode执行静态代码分析

Xcode执行静态代码分析

作者: 墨狂之逸才 | 来源:发表于2015-12-25 18:41 被阅读313次

    参考资源链接:


    Static Analysis on iOS - Part I

    Static Analysis on iOS - Part II

    Xcode执行静态代码分析(这位大神就是根据官方文档写的博客)

    设置工程自动进行静态分析

    选中工程文件,在TARGETS的Build Settings选项中的搜索栏中搜索关键字,analyze during 'Build',在结果中将Analyze During 'Build'选项修改为YES。

    Xcode 7.2

    注:描述于IOS9.2下

    苹果文档:执行静态代码分析

    Performing Static Code Analysis

    Find flaws—potential bugs—in the source code of a project with the static analyzer built into Xcode. Source code may have subtle细微的 errors that slip by the compiler编译器 and manifest themselves only at runtime, when they could be difficult to identify and fix.

    1.Choose Product > Analyze.

    2.In the issue navigator, select an analyzer message.

    3.In the source editor, click the corresponding message.

    4.Use the pop-up menu in the analysis results bar above the edit area to study the flow path of the flaw.

    5.Edit the code to fix the flaw.

    The video shows the process of looking at a flaw in the source file SKTText.m.

    官方文档Xcode执行静态代码分析视频教程

    The Xcode static analyzer parses the project source code and identifies these types of problems:

    1.Logic flaws, such as accessing uninitialized variables and dereferencing null pointers

    2.Memory management flaws, such as leaking allocated memory

    3.Dead store (unused variable) flaws

    4.API-usage flaws that result from not following the policies required by the frameworks and libraries the project is using

    You can suppress false positive messages from the analyzer using assertions, attributes, or pragma directives.

    When you analyze a project for the first time, you may uncover a lot of issues. But if you run the static analyzer regularly and fix the flaws it uncovers, you should see fewer problems in subsequent analyses. Analyze early; analyze often. It’s good for the code.

    Note that if the static analyzer reports no problems, you can't assume that there are none. The tool cannot necessarily detect all the flaws in the source code

    相关文章

      网友评论

        本文标题:Xcode执行静态代码分析

        本文链接:https://www.haomeiwen.com/subject/yfxbhttx.html