xcode Swift 调试器在导入 ObjC 框架时不显示变量值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31219422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:25:12  来源:igfitidea点击:

Swift debugger does not show variable values when importing ObjC framework

xcodedebuggingframeworksswift2xcode7-beta2

提问by LearnCocos2D

When I create a new OS X "Game" project with Sprite Kit, and set a breakpoint anywhere I can see the variable values just fine:

当我使用 Sprite Kit 创建一个新的 OS X“游戏”项目,并在我能看到变量值的任何地方设置一个断点时:

enter image description here

在此处输入图片说明

Then I change the code to import my own framework (TilemapKit) which is a pure Objective-C framework:

然后我更改代码以导入我自己的框架 (TilemapKit),它是一个纯 Objective-C 框架:

import SpriteKit
import TilemapKit

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        print("dang!")
    }
}

No other changes made. I'm not even using any of the TilemapKit code (yet). When the breakpoint triggers, I see this:

没有进行其他更改。我什至没有使用任何 TilemapKit 代码(还)。当断点触发时,我看到:

enter image description here

在此处输入图片说明

The entire project stops being debuggable as far as observing variable values goes. This behavior is perfectly consistent. Without the framework import I can debug again.

就观察变量值而言,整个项目不再可调试。这种行为是完全一致的。如果没有框架导入,我可以再次调试。

Since I'm on Xcode 7 beta (7A121l) and OS X 10.11 developer preview I know this could simply be a (temporary) bug.

由于我使用的是 Xcode 7 beta (7A121l) 和 OS X 10.11 开发者预览版,我知道这可能只是一个(临时)错误。

Command line Tiles are set to use the Xcode 7.0 version btw. I tried enabling modules in the framework target, made sure the deployment target is the same (10.11), disabled symbol stripping. I added a Bridging Header and #imported the TilemapKit framework in it (removing the Swift import in that case would still give me the non-debuggable app, so it doesn't seem to matter how or where I import the framework).

命令行 Tiles 设置为使用 Xcode 7.0 版本顺便说一句。我尝试在框架目标中启用模块,确保部署目标相同(10.11),禁用符号剥离。我添加了一个桥接头并在其中 #imported TilemapKit 框架(在这种情况下删除 Swift 导入仍然会为我提供不可调试的应用程序,因此我导入框架的方式或位置似乎无关紧要)。

Does anyone have a suggestion on what could cause this behavior and how I might go about fixing it - or at least how I could try to narrow down the issue?

有没有人对可能导致这种行为的原因以及我如何解决它提出建议 - 或者至少我可以尝试缩小问题的范围?

Is the culprit more likely to be connected to the project's vs the framework's build settings? Do I need to enable something in the app project to make it compatible with ObjC frameworks? (I already got -ObjC in the Other Linker flags)

罪魁祸首是否更有可能与项目的构建设置和框架的构建设置相关联?我是否需要在应用程序项目中启用某些内容以使其与 ObjC 框架兼容?(我已经在其他链接器标志中获得了 -ObjC)



UPDATE:

更新:

I ran po selfin the debug console and found this notice:

po self在调试控制台中运行,发现了这个通知:

<built-in>:3:6: error: module 'TilemapKit' was built in directory '/TilemapKit.framework' but now resides in directory './TilemapKit.framework'
#define __clang_major__ 7
     ^
missing required module 'TilemapKit'
Debug info from this module will be unavailable in the debugger.

How come the framework build directory changed? And why would that matter and how to fix this?

框架构建目录怎么变了?为什么这很重要以及如何解决这个问题?

PS: the same framework in a new ObjC app can be debugged just fine.

PS:同一个框架在新的ObjC app中调试就好了。

采纳答案by LearnCocos2D

I got a message from an Apple developer stating that they've observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project.

我收到了来自 Apple 开发人员的一条消息,指出他们已经观察到这个问题,并且可以通过将 .framework 移动到项目的子文件夹来修复它。

Apparently the module .. was built in directoryerror appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR).

显然,module .. was built in directory仅当 .framework 与 .xcodeproj aka 位于同一文件夹中时才会出现错误$(PROJECT_DIR)

However moving the framework to a subfolder didn't fix the issue in my case, but it's still worth a try until this gets fixed in a newer Xcode 7 beta (still occurs in beta 3).

然而,将框架移动到子文件夹并没有解决我的问题,但在更新的 Xcode 7 beta 中修复此问题之前仍然值得一试(仍然出现在 beta 3 中)。

回答by Hugo

In my case this was happening because of redundant importstatements in my project.

在我的情况下,这是因为import我的项目中有多余的陈述。

My project mixes swift and objc files, so I have import statements in the bridging_header.hfile.

我的项目混合了 swift 和 objc 文件,所以我在bridging_header.h文件中有导入语句。

In my bridging_header.hI had #import blah.h

在我的bridging_header.h我有#import blah.h

In one of the swift files, I was importing a redundant header from a framework @import blah // From blah.framework

在其中一个 swift 文件中,我从框架中导入了一个冗余标头 @import blah // From blah.framework

I removed the redundant import from the swift file, that seems to have fixed it.

我从 swift 文件中删除了多余的导入,这似乎已经修复了它。

回答by Charles Barros

I had this issue a while ago. In my case the Prefix.pch was beeing included inside the Bridging-Header.h. This is not a issue per so, but inside my Prefix.pch there was many C includes that make the lldb fail to import the Bridging-Header. So I removed the "#import Prefix.pch" from the Bridging-Header and copied just the "#includes" to the obj-c files that I need to use in swift.

不久前我遇到了这个问题。在我的例子中,Prefix.pch 被包含在 Bridging-Header.h 中。这本身不是问题,但在我的 Prefix.pch 中,有许多 C 包含使 lldb 无法导入桥接头。所以我从 Bridging-Header 中删除了“#import Prefix.pch”,并将“#includes”复制到我需要在 swift 中使用的 obj-c 文件。

回答by Ar No

  1. The Optimization level is not set to None for the Debug configuration. Be sure to set it to None for Objective-C apps as shown in Figure 1 and for Swift apps as shown in Figure 2.
  1. 调试配置的优化级别未设置为无。对于 Objective-C 应用程序(如图 1 所示)和 Swift 应用程序(如图 2 所示),请务必将其设置为 None。

Figure 1 & Figure 2

Figure 1 & Figure 2

  1. The Build Configuration pop-up menu is set to Release in the scheme editor's Run action settings pane. In Xcode, open the scheme editor by choosing Product > Scheme > Edit Scheme…, select the Run action for your app in the scheme actions pane, then set Build Configuration to Debug as seen in Figure 3.
  1. 在方案编辑器的运行操作设置窗格中,构建配置弹出菜单设置为发布。在 Xcode 中,通过选择 Product > Scheme > Edit Scheme... 打开方案编辑器,在方案操作窗格中为您的应用选择运行操作,然后将构建配置设置为调试,如图 3 所示。

Figure 3

Figure 3

回答by Justin Domnitz

I can confirm this is happening in Xcode Version 7.0 beta 4 (7A165t). I had to remove my ObjC framework to get Debugging values to return. If removing your framework isn't an option, the print method is old-school debugging, but still works.

我可以确认这是在 Xcode Version 7.0 beta 4 (7A165t) 中发生的。我必须删除我的 ObjC 框架才能返回调试值。如果删除您的框架不是一个选项,打印方法是老式的调试,但仍然有效。

回答by Meet

Go to Edit Scheme on left top corner.

转到左上角的编辑方案。

And change the configurations to Debug, if it is release here

并将配置更改为调试,如果是发布 here