swift - 是否可以使用类 Label 类型声明 Computed 属性和 Observers?

标签 swift

我是 swift 的新手,任何人都可以帮助我理解

目的是什么?我应该使用class标签类型!

是否可以使用 class Label 类型声明 Computed 属性和 Observers

两者兼而有之?

谢谢

最佳答案

类型属性 可以使用staticclass 关键字创建

  1. 计算属性 可以使用 class 以及 static 关键字创建。
  2. Property observers 不允许使用 class 关键字。它们只能与 static 一起使用。

示例:

class First
{
    class var x : Int{
        return 3
    }

    static var y : Int{
        return 2
    }

//    error: class stored properties not supported in classes
//    class var z = 10 {
//        willSet{
//            print(newValue)
//        }
//    }

    static var w = 30 {
        willSet{
            print(newValue)
        }
    }
}

关于swift - 是否可以使用类 Label 类型声明 Computed 属性和 Observers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601223/

相关文章:

ios - CAEmitterCell 颜色属性不起作用

ios - 如何为 Xcode 6 创建自定义 Swift 文件模板?

ios - Swift 2 toInt() 不工作

swift - CTRL + 拖动到新创建的 UIViewController 文件中

ios - 解析推送通知添加新操作

Swift 如何通过 dispatch_queue 更新 tableview 单元格

ios - 从 Parse 检索多个图像的更好方法

ios - 如何比较 2 个 UIColor 对象,它们是日志中的 kCGColorSpaceModelRGB 和 UIExtendedSRGBColorSpace 实例?

ios - UITableView 单元格嵌入 View Controller 自动调整大小?

ios - 在后台保存导致响应时间延迟(iOS)