gpt4 book ai didi

swift - 错误: use of undeclared type '$__lldb_context' in NSAttributedString extension

转载 作者:行者123 更新时间:2023-12-03 15:03:54 26 4
gpt4 key购买 nike

给定以下Swift代码,将其保存在bug.swift中,并使用Xcode 8.2.1或Xcode 8.3 beta 2:

import Foundation

protocol MyProtocol {
func foo() -> String
}

extension MyProtocol {
func foo() -> String {
return "\(self)"
}
}

extension String: MyProtocol {}
extension NSAttributedString: MyProtocol {}

let normal = "normal".foo()
let attributed = NSAttributedString(string: "attributed", attributes: [:]).foo()

运行以下命令:
swiftc -g bug.swift
lldb bug

LLDB启动。现在,运行这些命令,并观察输出。在我传递 9的地方,传递您的 bug.swift中包含 return "\(self)"的行:
(lldb) target create "bug"
Current executable set to 'bug' (x86_64).
(lldb) b 9
Breakpoint 1: where = bug`(extension in bug):bug.MyProtocol.foo () -> Swift.String + 19 at bug.swift:9, address = 0x0000000100001e53
(lldb) run
Process 16370 launched: '/Users/zev/Desktop/bug' (x86_64)
Process 16370 stopped
* thread #1: tid = 0x31730e, 0x0000000100001e53 bug`MyProtocol.foo(self="normal") -> String + 19 at bug.swift:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100001e53 bug`MyProtocol.foo(self="normal") -> String + 19 at bug.swift:9
6
7 extension MyProtocol {
8 func foo() -> String {
-> 9 return "\(self)"
10 }
11 }
12
(lldb) po self
"normal"


(lldb) c
Process 16370 resuming
Process 16370 stopped
* thread #1: tid = 0x31730e, 0x0000000100001e53 bug`MyProtocol.foo(self=0x00007fff5fbff480) -> String + 19 at bug.swift:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100001e53 bug`MyProtocol.foo(self=0x00007fff5fbff480) -> String + 19 at bug.swift:9
6
7 extension MyProtocol {
8 func foo() -> String {
-> 9 return "\(self)"
10 }
11 }
12
(lldb) po self
error: <EXPR>:1:11: error: use of undeclared type '$__lldb_context'
extension $__lldb_context {
^~~~~~~~~~~~~~~

error: <EXPR>:18:5: error: use of unresolved identifier '$__lldb_injected_self'
$__lldb_injected_self.$__lldb_wrapped_expr_2(
^~~~~~~~~~~~~~~~~~~~~

第一次达到断点时,我们就符合 StringMyProtocol的要求,并且我们可以成功实现 po self

但是,第二次达到断点时,我们处于 NSAttributedStringMyProtocol的一致性,并且LLDB打印出乱码,而不是 po self的预期输出。

为什么LLDB有时无法打印任何有用的信息?这是一个人为的示例,但是我在日常使用LLDB时经常遇到这个问题。

最佳答案

根据Swift错误报告程序上的this answer指出,该错误已在某个时间点修复。我在Swift 5.2中进行了测试,并确认它已修复🎉

关于swift - 错误: use of undeclared type '$__lldb_context' in NSAttributedString extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42081127/

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