zoukankan      html  css  js  c++  java
  • swift init 初始化

    class PropertiesClass1 {
        var a = "Stringa"
        init() {
            print("初始化")
        }
    
    
    }
    
    class PropertiesClass2 {
        var id  = 0
        //lazy 懒加载,只有使用的时候才触发
        lazy var properties1 = PropertiesClass1()
    
        //初始化必须全部初始化所有属性,或者为Options
        var name: String? 
    
        //geter seter
        var qq: String {
            //geter seter 里面不能使用自己属性,否则会死循环
            get {
                return self.name!
            }
            set {
                self.name = newValue
            }
        }
        //只读属性
        var height: Int {
            return 180
        }
    
        var address: String = "xxx" {
            willSet {
                print(" 新值(newValue)")
            }
    
            didSet {
                print("旧值 (oldValue)")
            }
        }
    
        var function_properties = {return "properties"}()
    
        
    }
    
    var properties2 = PropertiesClass2()
    
    print(properties2.properties1)
    
    
    properties2.qq = "65683264"
    print(properties2.qq)
    
    print(properties2.height)
    // properties2.height = 2
    
    properties2.address = "ca"
    
    print(properties2.function_properties)
  • 相关阅读:
    正则表达式入门教程
    js获取class
    锋利的jQuery第6章 jQuery与Ajax的应用
    显示隐藏左侧菜单
    unicode转为汉字
    $.ajax
    .ashx文件
    c#正则表达式
    调试发现的小错误
    sql2005连接不到本地数据库
  • 原文地址:https://www.cnblogs.com/miss-once/p/5213840.html
Copyright © 2011-2022 走看看