gpt4 book ai didi

objective-c - 如何将 obj c 框架导入 swift 桥接头?

转载 作者:行者123 更新时间:2023-11-28 10:19:37 25 4
gpt4 key购买 nike

在将框架 header 导入我的项目时,我总是发现问题。例如,我在这张截图上的小试用项目。导入 Facebook SDK header 时我做错了什么?这是一个非常简单的步骤,但我无法找出它有什么问题。我什至像在 Facebook 开发者网站上一样一步一步地跟进。

Screenshot

编辑:对不起,也许我不清楚。桥接 header 已设置,我已在build设置中设置桥接 header 位置路径。这就是它产生错误的原因,因为它包含在编译中。问题是,使用当前导入 Facebook SDK 和桥接 header 的设置,我无法将 Facebook SDK 导入桥接 header 。

我尝试过的事情:

  • #import "FBSDKCoreKit/FBSDKCoreKit.h"
  • #import <FBSDKCoreKit/FBSDKCoreKit.h>
  • #import "FBSDKCoreKit.h"
  • #import <FBSDKCoreKit.h>
  • #import "FBSDKCoreKit.framework/FBSDKCoreKit.h"
  • #import <FBSDKCoreKit.framework/FBSDKCoreKit.h>

它们都不起作用(它们都像屏幕截图一样产生错误,这意味着桥接 header 很好并且包含在编译中,但它找不到我引用的 header )。

最佳答案

制作一个 Obj C Bridging:File -> New -> Source -> Header File -> Name as AppName-Bridging-Header.

添加以下内容(例如在 SDWebImage 的情况下):

  #ifndef AppName_AppName_Bridging_Header_h
#define AppName_AppName_Bridging_Header_h

#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
#endif

or

#import "UIImageView+WebCache.h"

注意:build设置,在 Swift Compiler - Code Generation 中,确保 Objective-C Bridging Header build设置下有桥接头文件的路径。 - 它像 testSD/testSD-Bridging-Header.h 或 testSD-Bridging-Header.h (打开项目文件夹并找到头文件路径)

@Chen:在你的情况下,尝试添加“-ObjC”链接器标志。

Select the project file from the project navigator on the far left side of the window.

Select the target for where you want to add the linker flag.

Select the “Build Settings” tab.Choose “All” to show all Build Settings.

Scroll down to the “Linking” section, and double-click to the right of where it says “Other Linking Flags”.

A box will appear, Click on the “+” button to add a new linker flag.
Type “-ObjC” (no quotes) and press enter.

关于objective-c - 如何将 obj c 框架导入 swift 桥接头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36715069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com