How to initialize properties that depend on each other

后端 未结 4 965
心在旅途
心在旅途 2020-11-21 05:10

I want a picture to move to the bottom. If I press a button the pic should move down by 1.

I added the picture and a button:

var corX = 0
var corY =         


        
4条回答
  •  我在风中等你
    2020-11-21 06:00

    Your dependent property needs to be:

    1. lazy
    2. Have an explicit : Type
    3. Use self. to access other properties

    Example:

    let original = "foo"
    
    // Good:
    lazy var depend: String = self.original
    
    // Error:
         var noLazy: String = self.original // Error: Value of type '(NSObject) -> () -> URLData' has no member 'original'
    lazy var noType         = self.original // Error: Value of type '(NSObject) -> () -> URLData' has no member 'original'
    lazy var noSelf: String =      original // Error: Instance member 'original' cannot be used on type 'YourClass'
    

提交回复
热议问题