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
Convert createY()
to a global or class function that accepts x
as an argument and returns a y
.
func createY(x: String) -> String {
return x + "_test" // this computation could be much more complex
}
Then just call it normally from your init
.
class MyClass {
let x: String
let y: String
init(x: String) {
self.x = x
self.y = createY(x)
}
}