ios 什么是伞头?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31238761/
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
What is an umbrella header?
提问by ruveena
What is basically an umbrella header? What is its use? I got a warning as shown below. What does this mean?
什么是基本的伞头?它的用途是什么?我收到了如下所示的警告。这是什么意思?
<module-includes>:1:1: warning: umbrella header for module 'XCTest' does not include header 'XCTextCase+AsynchronousTesting.h' [-Wincomplete-umbrella]
#import "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/Headers/XCTest.h"
采纳答案by Glorfindel
The umbrella headeris the 'master' header file for a framework. Its use is that you can write
所述伞头为框架的“主”头文件。它的用途是你可以写
#import <UIKit/UIKit.h>
instead of
代替
#import <UIKit/UIViewController.h>
#import <UIKit/UILabel.h>
#import <UIKit/UIButton.h>
#import <UIKit/UIDatePicker.h>
and so on.
等等。
For me, <XCTest/XCTestCase+AsynchronousTesting.h>
is included in <XCTest/XCTest.h>
. Maybe it is not for you? In that case, add the
对我来说,<XCTest/XCTestCase+AsynchronousTesting.h>
包含在<XCTest/XCTest.h>
. 也许它不适合你?在这种情况下,添加
#import <XCTest/XCTestCase+AsynchronousTesting.h>
manually.
手动。
回答by yoAlex5
umbrella header
- iOS framework
or library
on Objective-C
can have a header file that contains references to all the other headers in that project.
umbrella header
- iOS设备framework
或library
上Objective-C
可以包含在该项目中的所有其他头文件引用的头文件。
When you create a framework target Xcode will automatically generate <targer_name.h>
file. It should has the same name as Product Name
当您创建框架目标时,Xcode 会自动生成<targer_name.h>
文件。它应该具有相同的名称Product Name
Build Settings
:
Build Settings
:
Product Name
- default value is$(TARGET_NAME:c99extidentifier)
Product Module Name
- default value is$(PRODUCT_NAME:c99extidentifier)
Product Name
- 默认值为$(TARGET_NAME:c99extidentifier)
Product Module Name
- 默认值为$(PRODUCT_NAME:c99extidentifier)
For example <umbrella_name.h>
looks like
例如<umbrella_name.h>
看起来像
#import "header_1.h"
#import "header_2.h"
As a result you can use the next syntax
因此,您可以使用下一个语法
#import <umbrella_name.h>
instead of
代替
#import <header_1.h>
#import <header_2.h>
Also umbrella header
is also required by the typical module map
structure[About][Manually creation]
此外umbrella header
,还需要通过典型module map
结构[关于] [手动创建]
On practice when you create a Framework
on Objective-C
[Example]or Swift
[Example]this file will be created automatically with <product_name>
在实践中,当您Framework
在Objective-C
[Example]或Swift
[Example]上创建一个时,此文件将自动创建<product_name>
Importing Objective-C
into Swift
within a Framework Target
In the umbrella header, import every Objective-C header you want to expose to Swift.
在伞头文件中,导入每个你想暴露给 Swift 的 Objective-C 头文件。
Swift sees every header you expose publicly in your umbrella header. The contents of the Objective-C files in that framework are automatically available from any Swift file within that framework target, with no import statements. Use classes and other declarations from your Objective-C code with the same Swift syntax you use for system classes.
Swift 会在你的伞头文件中看到你公开的每一个头文件。该框架中的 Objective-C 文件的内容可从该框架目标中的任何 Swift 文件中自动获取,无需导入语句。使用 Objective-C 代码中的类和其他声明,使用与系统类相同的 Swift 语法。