简体   繁体   English

无法分配给属性“tabBarController”是一个只能获取的属性

[英]Cannot assign to property 'tabBarController' is a get-only property

I have declared a global variable:我已经声明了一个全局变量:

var tabBarController: UITabBarController?

Now when I try to assign to this global variable inside my UITabBarController class:现在,当我尝试在我的UITabBarController类中分配给这个全局变量时:

override func viewDidLoad() {
        tabBarController = self
}

I receive this error:我收到此错误:

Cannot assign to property 'tabBarController' is a get-only property无法分配给属性“tabBarController”是一个只能获取的属性

Why am I getting this?为什么我得到这个?

Your own property collides with an already existing property of the same name that every UIViewController has:您自己的属性与每个UIViewController具有的同名的现有属性发生冲突:

tabBarController - The nearest ancestor in the view controller hierarchy that is a tab bar controller. tabBarController - 视图控制器层次结构中最近的祖先是选项卡栏控制器。

var tabBarController: UITabBarController? { get }

As you can clearly see that property is get -only.正如您可以清楚地看到该属性是get -only。

If you choose a different name for that property you will be fine.如果您为该属性选择不同的名称,您会没事的。 Or you configure all the connections in the interface builder beforehand.或者您事先在界面构建器中配置所有连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法分配给属性:'inputAccessoryView'是一个get-only属性 - Cannot assign to property: ‘inputAccessoryView’ is a get-only property 无法分配给属性:“ size”是仅获取属性Swift - Cannot assign to property: 'size' is a get-only property Swift 无法分配给属性:“值”是一个只能获取的属性 RxSwift - - Cannot assign to property: 'value' is a get-only property RxSwift - 无法分配给属性:“ b0”是只读属性 - Cannot assign to property: 'b0' is a get-only property 无法分配给属性:“popupHeight”是一个只能获取的属性 - Cannot assign to property: 'popupHeight' is a get-only property 无法分配给属性:“输出”是仅获取属性 - Cannot assign to property: 'outputs' is a get-only property 无法分配给属性'observationTime'是一个get-only属性 - Cannot assign to property 'observationTime' is a get-only property Swift无法通过下标分配:“ peerDeviceSettings”是仅获取属性” - Swift Cannot assign through subscript: 'peerDeviceSettings' is a get-only property" 快速在键盘上方添加视图,但出现错误无法分配给属性:“ inputAccessoryView”是仅获取属性 - Swift adding view above keyboard getting Error Cannot assign to property: 'inputAccessoryView' is a get-only property 我该如何解决这个问题“无法分配给属性:'typ' 是一个只能获取的属性” - How can I solve this problem “Cannot assign to property: 'typ' is a get-only property”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM