gpt4 book ai didi

swift - 无法形成对 NSTextView 类实例的弱引用

转载 作者:IT王子 更新时间:2023-10-29 05:33:50 24 4
gpt4 key购买 nike

仅使用 Swift,这是我在 AppDelegate.swift 中的代码:

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet var window: NSWindow
@IBOutlet var textField: NSTextView

@IBAction func displaySomeText(AnyObject) {
textField.insertText("A string...")
}

func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
}

func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}


}

在界面生成器中,我连接了一个对象以接收来自按钮的输入,然后输出转到 TextView 。当我按下按钮时,我试图让 TextView 填充一些文本。

我也用文本字段尝试过此操作,但没有收到错误,但听到“咚”的错误声音并且没有做任何其他事情。根据我的理解,在 Objective-C 中,您必须使用 (assign) 参数才能使其正常工作。

我做错了什么?

最佳答案

由于 Cocoa 和 AppKit 的历史问题,您不能存储对 NSTextView 的弱引用。参见 details in the Clang documentation . NSTextViewNSTextView.h 中被标记为 NS_AUTOMATED_REFCOUNT_WEAK_UNAVAILABLE , 还有 a few other classes去监视。

您是否尝试过 Swift 无主引用而不是弱引用,这有点像 Objective-C 的赋值(您将在 Objective-C 中用于 NSTextView socket 的内容)?

关于swift - 无法形成对 NSTextView 类实例的弱引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24062437/

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