Core Graphics Tutorial: Getting Started Article issues

The code is not exactly correct. If I follow code literally it doesn’t compile. For example:

import UIKit

@IBDesignable class CounterView: UIView {
  private struct Constants {
    static let numberOfGlasses = 8
    static let lineWidth: CGFloat = 5.0
    static let arcWidth: CGFloat = 76
    static var halfOfLineWidth: CGFloat {
      return lineWidth / 2
  @IBInspectable var counter: Int = 5
  @IBInspectable var outlineColor: UIColor =
  @IBInspectable var counterColor: UIColor =
    >   override func draw(_ rect: CGRect) {
    >   }
    > }

lineWidth is in Constants struct. So halfOfLineWidth parameter will show error.

Hi @vidocaz, could you share the error please?

hi @vidocaz,
It will not show an error, because you are not modifying the lineWidth variable, you are returning the value of lineWidth / 2

Secondly, if you feel that it will show an error due to it being part of the Constants structure, then so is the halfOfLineWidth, so it is all good.

If there is something else that you wanted to highlight, please reiterate the question.


This topic was automatically closed after 166 days. New replies are no longer allowed.