Xcode 创建了一个返回错误“缺少 setter 或实例变量"的 Xib 文件 [英] Xcode created a Xib file that returns error "missing setter or instance variable"
问题描述
在花了一整个下午和晚上试图了解它是如何工作的之后,我尝试在这里问以解决我的问题.
After spent all the afternoon and the night to try understand how it works, I try to ask here to resolve my problem.
我在 Xcode 中创建了一个 Cocoa 应用程序.我删除了默认的 MainMenu.xib 文件以创建我自己的文件.
I've created a Cocoa App in Xcode. I deleted the default MainMenu.xib file in order to create my own file.
现在我有:
一个名为
AppDelegate.swift
的文件,其中包含以下部分代码
a file named
AppDelegate.swift
with the following part of code
@NSApplicationMain类 AppDelegate: NSObject, NSApplicationDelegate {
@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
一个名为 Window.swift
的文件,代码如下:
a file named Window.swift
with the following code:
类窗口:NSWindowController {
class Window: NSWindowController {
一个名为 Window.xib
的文件没有连接(插座集),因为我试图了解如何设置它,所以我删除了所有已创建的文件以尝试重新创建它.
A file named Window.xib
that has no connection (outlet set) since I try to understand how set it so I have deleted all the already created in order to try to recreate it.
问题是,即使我可以在 Window : NSWindowsController
类中链接一个按钮(以前用 Interface Builder 插入到窗口中),它也会返回错误
The problem is that, even I can link a button (previously inserted with the Interface Builder into the window) in the Window : NSWindowsController
class, it return the error
Failed to connect (button) outlet from (NSApplication)
to (NSButton): missing setter or instance variable
我不明白为什么因为唯一的连接是现在定义的连接并且没有更多可能的连接可以做(我试图链接屏幕周围的一些组件以查看一些锚定区域但没有出现).
I don't understand why since the only connection is the connection now defined and no more possible connection are possible to do (I've tried to link some component around the screen in order to see some anchor zone but no appears).
所以,即使有一些问题会分析这个问题,因为用户做错了什么,我也会尝试要求解释连接是如何执行的,以便重新创建连接并了解问题出在哪里.
So, even if there are some questions that analyse this problem given the answer that the user have done something wrong, I try to ask to explain how the connection are performed in order to recreate it and understand where is the problem.
仅出于完整性考虑,在 Windows.xib 中,下层文件的所有者、第一响应者或应用程序会在连接检查器面板中显示链接.
Only for completeness, in the Windows.xib, nether File's Owner, First Responder or Application shows links in the Connections inspector panel.
推荐答案
- 移除 AppDelegate.swift 中的 @NSApplicationMain 注解
//@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
- 在项目中添加 main.swift .例如
import Cocoa
autoreleasepool {
let delegate = AppDelegate()
// NSApplication delegate is a weak reference,
// so we have to make sure it's not deallocated.
withExtendedLifetime(delegate, {
let application = NSApplication.shared
application.delegate = delegate
application.run()
application.delegate = nil
})
}
这篇关于Xcode 创建了一个返回错误“缺少 setter 或实例变量"的 Xib 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!