Information Hiding the “Swifter” way?

前端 未结 2 1521
失恋的感觉
失恋的感觉 2021-02-11 04:19

I have a question regarding object oriented design principles and Swift. I am pretty familiar with Java and I am currently taking a udacity course to get a first hands on in Swi

2条回答
  •  你的背包
    2021-02-11 04:54

    I do it a bit like in Obj-C:

    class MyClass
      private var _something:Int
      var something:Int {
        get {return _something}
    // optional: set { _something = newValue }
      }
      init() { _something = 99 }
    }
    
    ...
    let c = MyClass()
    let v = c.something
    

    Above is a primitive example, but handled stringent it works as a good pattern.

提交回复
热议问题