Sample Project: http://cl.ly/1I0c2E3D0x1z
示例项目:http://cl.ly/1I0c2E3D0x1z
I'm a little confused. I want to use Apple's image blurring library in my Swift project, but it seems like adding the .h and .m, putting the .h in my bridging header and compiling isn't sufficient.
我有点困惑。我想在我的Swift项目中使用Apple的图像模糊库,但似乎添加了.h和.m,将.h放在我的桥接标题中并且编译是不够的。
It gives me tons of error (actually stops reporting them eventually) at compile time, the first bunch saying "Expected a type" and taking issue with UIImage
.
它在编译时给了我很多错误(实际上最终停止报告它们),第一批说“预期类型”并且对UIImage有疑问。
What am I doing wrong?
我究竟做错了什么?
2 个解决方案
#1
8
The problem is that the compiler doesn't recognize UIImage
.
问题是编译器无法识别UIImage。
That is because you only import Foundation
but UIImage
is declared in UIKit
.
那是因为你只导入了Foundation,但在UIKit中声明了UIImage。
Change line 50 in the UIImageEffects.h
from
更改UIImageEffects.h中的第50行
#import <Foundation/Foundation.h>
to
@import UIKit;
After that the projects builds without any problems!
之后,项目构建没有任何问题!
In your Objective-C projects you most probably imported UIKit
in your .pch
precompiled headers file.
在Objective-C项目中,您最有可能在.pch预编译头文件中导入UIKit。
#2
0
You need to add it to your target's build settings:
您需要将其添加到目标的构建设置:
1.In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.
1.在Xcode中,如果你进入目标的构建设置,并一直向下滚动,你会找到一个“Swift编译器 - 代码生成”部分。
2.Set "Objective-C Bridging Header" to <#PROJECT_NAME>Bridging-Header.h
2.将“Objective-C Bridging Header”设置为<#PROJECT_NAME> Bridging-Header.h
3.Now create a Bridging-Header.h file.Import sdk to Bridging-Header.h.
3.现在创建一个Bridging-Header.h文件。将sdk导入Bridging-Header.h。
You did the same?If not then try this. This worked for me.
你做了同样的事情吗?如果没有,那就试试吧。这对我有用。
#1
8
The problem is that the compiler doesn't recognize UIImage
.
问题是编译器无法识别UIImage。
That is because you only import Foundation
but UIImage
is declared in UIKit
.
那是因为你只导入了Foundation,但在UIKit中声明了UIImage。
Change line 50 in the UIImageEffects.h
from
更改UIImageEffects.h中的第50行
#import <Foundation/Foundation.h>
to
@import UIKit;
After that the projects builds without any problems!
之后,项目构建没有任何问题!
In your Objective-C projects you most probably imported UIKit
in your .pch
precompiled headers file.
在Objective-C项目中,您最有可能在.pch预编译头文件中导入UIKit。
#2
0
You need to add it to your target's build settings:
您需要将其添加到目标的构建设置:
1.In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.
1.在Xcode中,如果你进入目标的构建设置,并一直向下滚动,你会找到一个“Swift编译器 - 代码生成”部分。
2.Set "Objective-C Bridging Header" to <#PROJECT_NAME>Bridging-Header.h
2.将“Objective-C Bridging Header”设置为<#PROJECT_NAME> Bridging-Header.h
3.Now create a Bridging-Header.h file.Import sdk to Bridging-Header.h.
3.现在创建一个Bridging-Header.h文件。将sdk导入Bridging-Header.h。
You did the same?If not then try this. This worked for me.
你做了同样的事情吗?如果没有,那就试试吧。这对我有用。