How to import Apple UIImage + Effects category into my Swift app?

Project example: http://cl.ly/1I0c2E3D0x1z

I'm a little confused. I want to use the Apple image blur library in my Swift project, but it seems that adding .h and .m, placing .h in my header and compiling isn is enough.

This gives me a lot of errors (actually ceases to report them at the end) at compile time, the first help is "Expected Type" and a problem with UIImage .

What am I doing wrong?

+5
source share
2 answers

The problem is that the compiler does not recognize UIImage .

This is because you only import Foundation , but UIImage declared in UIKit .

Change line 50 in UIImageEffects.h from

 #import <Foundation/Foundation.h> 

to

 @import UIKit; 

After this, projects are built without problems!


In your Objective-C projects, you most likely imported UIKit into your file with precompiled .pch headers.

+8
source

You need to add it to your target build settings:

1. In Xcode, if you go to build settings for your purpose and scroll all the way down, you will find the "Swift Compiler - Code Generation" section.

2.Set "Objective-C Bridging Header" in <#PROJECT_NAME> Bridging-Header.h

3. Now create the Bridging-Header.h.Import sdk file for Bridging-Header.h.

Did you do the same? If not, try this. It worked for me.

0
source

Source: https://habr.com/ru/post/1207371/


All Articles