Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,868 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.