> For the complete documentation index, see [llms.txt](https://yongpenglovemimi123.gitbook.io/henry/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yongpenglovemimi123.gitbook.io/henry/swift/jian-ce-swift-xiang-mu-zhong-wei-shi-yong-de-lei-fang-fa-shu-xing.md).

# 检测Swift项目中未使用的类 方法 属性

> 当前环境： Xcode10.0 Swift4.2 iOS SDK 12.1

## 检查项目中 Swift 类，方法，属性 未使用情况

## 项目地址

`homepage:` <https://github.com/zColdWater/swift-scripts>

### 使用

```
1. cd <项目根目录>
2. 将unused.rb脚本文件 路径填入终端即可， 或者直接将 unused.rb 拖拽至终端。
```

### 输出

```
Total items to be checked 13
Total unique items to be checked 13
Starting searching globally it can take a while
Item< var oop [] from: TestDemo/ViewController.swift:13:0>
Item< var poo [] from: TestDemo/ViewController.swift:15:0>
Item< func bcd [] from: TestDemo/ViewController.swift:29:0>
Item< class AppDelegate [] from: TestDemo/AppDelegate.swift:12:0>
Item< var window [] from: TestDemo/AppDelegate.swift:14:0>
Item< func applicationWillResignActive [] from: TestDemo/AppDelegate.swift:22:0>
Item< func applicationDidEnterBackground [] from: TestDemo/AppDelegate.swift:27:0>
Item< func applicationWillEnterForeground [] from: TestDemo/AppDelegate.swift:32:0>
Item< func applicationDidBecomeActive [] from: TestDemo/AppDelegate.swift:36:0>
Item< func applicationWillTerminate [] from: TestDemo/AppDelegate.swift:40:0>
```

### Xcode 集成

添加自定义 Build 脚本 *Custom Build Phase/Run Script* `~/Projects/swift-scripts/unused.rb xcode` ![](https://user-images.githubusercontent.com/119268/32348473-88080ed2-c01c-11e7-9de6-762aeb195156.png) ![](https://user-images.githubusercontent.com/119268/32348476-8af3a700-c01c-11e7-893f-013851568882.png)

### 已知问题：

* 像系统代理方法，或者给其他模块的 API，都会被标记为 unuse ，所以要人工确认，才可以去掉多余方法。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yongpenglovemimi123.gitbook.io/henry/swift/jian-ce-swift-xiang-mu-zhong-wei-shi-yong-de-lei-fang-fa-shu-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
