Saturday, June 13, 2026
HomeiOS Developmentios - Including perform parameter to view ends in error for current...

ios – Including perform parameter to view ends in error for current computed property

[ad_1]

I am attempting to move a perform into my view, which additionally has a calculated property as an init worth. Beforehand, the next code labored advantageous earlier than making an attempt so as to add the perform as an init property of my view:

var title: String
var desc: String {
    get {
        return self._desc
    }
    set {
        self._desc = newValue
        self.options = newValue.elements(separatedBy: "nn")
    }
}

personal var _desc: String = ""
personal var options:[String] = []

public init(title: String, desc: String) {
    self.title = title
    self.desc = desc
}

No Errors—all the pieces works as anticipated. However then after I add my perform to the view and within the init, immediately it’s erroring on the earlier line, as if my computed property was the issue:

var title: String
var desc: String {
    get {
        return self._desc
    }
    set {
        self._desc = newValue
        self.options = newValue.elements(separatedBy: "nn")
    }
}
var motion: () -> Void
personal var _desc: String = ""
personal var options:[String] = []

public init(title: String, desc: String, motion: @escaping () -> Void) {
    self.title = title
    self.desc = desc // Errors right here: "'self' used earlier than all saved properties are initialized"
    self.motion = motion
}

I’ve checked out all of the posts I can discover with this error, however all of them take care of circumstances unrelated to what I am seeing right here.

Does anybody perceive what is going on? Why would including one other parameter to a view set off this error for a computed property when in any other case it labored advantageous?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments