iOS import package

Frameworks
Frameworks, as the name suggests, is a framework, which is a third-party package that cannot see the source code and can be used directly.
Reference method in the project

OC  引用某一个文件,Frameworks一般会提供一个h文件引用全部其他文件
#import <JLRoutes/JLRoutes.h>
swift  引用一个包,相当于引用了Frameworks中的所有文件
import JLRoutes

Pods mode
Pods manages the encapsulated source code in iOS. It can be imported into the project as a video pod, which is equivalent to Frameworks that can see the source code and modify the source code. Some packages similar to Frameworks will not be generated, such as: GrowingIO (because in Import GrowingIO failed in swift)
reference method in the project

OC  引用某一个文件,Pods一般会提供一个h文件引用全部其他文件
#import <JLRoutes/JLRoutes.h>
swift  引用一个包,相当于引用了Pods中的所有文件
import JLRoutes

-Bridging-Header.h Bridging file
Bridging file, that is, the OC file can be called by bridging to Swift
1. In the use of swift, we can bridge the package (Frameworks/Pods), such as

#import <JLRoutes/JLRoutes.h>
#import <GrowingIO/Growing.h>

2. Never use

#import "JLRoutes.h"
#import "Growing.h"
Although there will be no misreporting, there will be a console printing variable problem
3. The OC code added in the project must be used

#import "JLRoutes.h"
#import "Growing.h"

import import method
If it is a single file, it needs to be imported and used directly; if it is a package

import AFNetworking

Bridging file generation:
Create a new swift file in the runner, and click the prompt to create a bridge file.
insert image description here
If in an OC project, create a .swift file for the first time
or in a Swift project, create an OC .h .m file for the first time
Then Xcode will create a bridging header file of "project name-Bridging-Header.h" for the project by default

This is a convenient way to create a Bridging-Header.h file,
and then delete the temporarily created .swift file or .h .m file.

How to manually create a Bridging-Header.h file?
1. Manually create a .h file of "Project Name-Bridging-Header.h" (standard naming is recommended)
2. Open TARGETS --> select the current target
3. Select Build Settins --> Search: Bridging
4. Set up Swift Path to "Object-C Bridging Header" under Compiler - General

路径: 项目名/BridgingHeader名.h:   SRSwiftDemo/SRSwiftDemo-Bridging-Header.h

路径: $(SRCROOT)/项目名/BridgingHeader名.h ( 我的项目文件是放在 Desktop 下的 ):   $(SRCROOT)/SRSwiftDemo/SRSwiftDemo-Bridging-Header.h

也就是: 根据设置的路径, 要能找到这个 Bridging-Header.h 文件

设置后 显示如 下图:

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44911775/article/details/132544875