0

I've been using this macro in Objctive-C:

#define viewWidth self.view.frame.size.width

I am trying to figure out how I can get the closest thing possible in swift?

any idea?

thank you

Kirsteins
  • 27,065
  • 8
  • 76
  • 78

1 Answers1

1

There is no support for macros in Swift. You could try declaring an extension:

extension UIViewController {
    var width: CGFloat {
        return self.view.frame.size.width
    }
}

Then use self.width instead of viewWidth.

Kirsteins
  • 27,065
  • 8
  • 76
  • 78