简体   繁体   English

# 通过自动创建的Bridging header 导入的Obj-C 类,Bridging header 似乎找到了但Swift 类不会

[英]# Imported Obj-C class through automatically created Bridging header, Bridging header seems to find it but Swift class won't

  1. I added the files directly to my project from finder to Xcode.我将文件直接添加到我的项目中,从 finder 到 Xcode。
  2. Bridging header was automatically created by Xcode.桥接头由 Xcode 自动创建。
  3. #import the Class into the Bridging header - no issues on the Bridging Header. #将类导入桥接头 - 桥接头没有问题。
  4. I try to instantiate Class var into swift class - " use of undeclared type " error shows up.我尝试将 Class var 实例化为 swift 类 - “使用未声明的类型”错误出现。

    • Notes: When I try to COMMAND + click on the #import I get the message "Symbol Not Found".注意:当我尝试COMMAND + 单击#import 时,我收到消息“找不到符号”。

You need to have your bridging filename set to the "Objective-C Bridging Header" field under the Swift Compiler section in Build Settings for it to be included by the Compiler.您需要将桥接文件名设置为 Build Settings 中 Swift Compiler 部分下的“Objective-C Bridging Header”字段,以便编译器包含它。在此处输入图片说明

"Symbol Not Found" is just an Xcode bug, I get that but I have no issues using bridged files. “找不到符号”只是一个 Xcode 错误,我明白了,但使用桥接文件没有问题。

Turns out that file ( A.swift ) that was trying to reference the "other file" ( B.swift ) had " test target membership " selected!事实证明文件(A.swift),这是尝试引用“其他文件”(B.swift)已经选择“测试目标会员”! So I either had to add the "other file"( B.swift ) to the test target membership or remove file ( A.swift ) from the test target membership.所以我要么不得不将“其他文件”( B.swift )添加到测试目标成员资格中,要么从测试目标成员资格中删除文件( A.swift )。 I hope that makes sense and that it is of help to someone.我希望这是有道理的,并且对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 桥接头和 Obj-C 类的可见性 - Swift Bridging Header and visibility of Obj-C class 未找到Swift / Obj-C桥接标头/导入失败 - Swift/Obj-C bridging header not found/failed to import 使用桥接头中导入的目标c类时,无法快速完成 - No completions in swift when using objective c class imported in bridging header 通过桥接头导入Obj-C文件后出错 - Errors after importing Obj-C files through bridging header 尽管桥接头工作正常,但无法在 Swift 中实例化 Obj C 类 - Can't Instantiate Obj C Class in Swift in spite of working bridging header 通过Obj-C桥接头将sqlite3.h导入Swift项目不起作用 - Importing sqlite3.h to a Swift project via a Obj-C bridging header doesn't work 当我在swift中导入OBJ-C类时,Xcode不会提示我添加一个Bridging-header.h - When I import OBJ-C classes in swift, Xcode doesn't prompt me to add a Bridging-header.h 从Swift 2项目中删除Obj-C桥接头后的错误 - Errors after removing Obj-C Bridging Header from Swift 2 Project Xcode 13 桥接 Header 似乎找到了我的 Obj-C 类 - Xcode 13 Bridging Header does seem to find my Obj-C classes 即使创建了Swift Bridging Header文件,也无法在Objective C中引用Swift类 - Not able to reference Swift Class in Objective C even though the Swift Bridging Header file is created
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM