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 Classes and Objects Classes and Their Methods

Emmet Lowry
Emmet Lowry
10,196 Points

not sure how to add to a property in the challange at the end of turning classes to structs

it asks me to add points to the width and height variables inside this method

Button.swift
class Button {
  var width: Double
  var height: Double

  init(width:Double, height:Double){
    self.width = width
    self.height = height
  }
  func incrementBy(points: Double){

  }
}

4 Answers

Hiya,

The function has a parameter passed into it called points, this contains the number that the width and height need to be increased by.

You could try:

self.width += points
self.height+= points

Or maybe a more sensible:

self.width = self.width + points
self.height = self.height + points

Let me know how you get on with those. My Xcode is rebuilding at the moment as I just did a fresh build of my Mac so I can't test those suggestions. If they don't work, I'll beback up and running in no tiem; I'll have a more detailed look for you then.

Steve.

Apologies - to be clear - both those suggestions need to go inside the func incrementBy method.

Emmet Lowry
Emmet Lowry
10,196 Points

Thanks for the answer Steve. It is more clear to me now

Emmet Lowry
Emmet Lowry
10,196 Points

could i ask you if i should learn objective c or is there any point since i learned swift

No problem with the suggested solution!

As for Obj-C & Swift. That depends - if you're totally new to programming, just go down the Swift route. The concepts you will learn are pretty much identical, particularly from the iOS perspective. If you want to be able to edit legacy apps in Obj-C, have a look through that too but I do belive they are both pretty easy to swith between.

The iOS bit is the challenge, not the Swift/Obj-C bit. Same with Android. Java is what it is but programming Android devices in Java is a whole separate thing.

I hope that helps - else, just shout!

Steve.