Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Properties Getter and Setter methods

Szymon Kadłuczka
Szymon Kadłuczka
8,762 Points

Multiple "newValue" values?

Is it possible to set multiple values for a setter of computed property? If so, how to do it since I only have one "newValue" ?

Hi Szymon,

Can you provide us with an example of what the outcome would look like? So that we could recommend other options.

Szymon Kadłuczka
Szymon Kadłuczka
8,762 Points

Well, for instance:

set { self.width = newValue self.height = newValue2 //<--- How to use more than one newValue ? }

You can't do that but you could do something crazy like

class Table {
    var width: Int
    var height: Int

    var widthTwo: Int
    var heightTwo: Int

    init(width: Int, height: Int, widthTwo: Int, heightTwo: Int) {
        self.width = width
        self.height = height
        self.widthTwo = widthTwo
        self.heightTwo = heightTwo


var myTable = Table(width: 5, height: 5, widthTwo: 10, heightTwo: 10)



Not sure that this would help

1 Answer

William Li
William Li
Courses Plus Student 26,865 Points

Is it possible to set multiple values for a setter of computed property?

No, you can't, Swift doesn't allow you to have multiple newValue for a setter of computed property.