Search code examples
iosswiftweak-referencesiboutletzbar-sdk

swift: weak cannot be applied to an outlet


I am using libzBar for scanning QRCode in swift but I am getting these errors.

errors image.

First error is about weak referencing and second is undeclared type. At first I thought I haven't included the ZBarReaderView.h but after checking the file Inspector I found that the files are correctly added as

file inspector image

I have already added a ZBarReaderView in Objective-C and it works fine. I have also viewed the sample project for adding an EmbeddedReader(ObjectiveC).

So I want to know why I am getting this error and how to remove this error?

Solution:

To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.


Solution

  • It looks like you didn't create a bridging header. Follow the Apple Docs to create one and then import ZBarReaderView.h in the bridging header.