Calling instance method during initialization in Swift

前端 未结 7 1544
别跟我提以往
别跟我提以往 2020-12-06 01:08

I am new to Swift and would like to initialize an object\'s member variable using an instance method like this:

class MyClass {
  var x: String
  var y: Stri         


        
7条回答
  •  心在旅途
    2020-12-06 02:04

    You can use in this approach

    class MyClass: NSObject {

            let x: String
            var y: String
    
            init(x: String) {
    
                self.x = x
                self.y = self.x + "_test"
                print(self.x)
                print(self.y)
            }
    }
    

提交回复
热议问题