Search code examples
iosibdesignable

Buildtime errors in IBDesignable for making gradient


I was trying to create custom options for gradient using IBDesignable following this tutorial, but I get unexpected errors even just coping code from tutorial

import UIKit

@IBDesignable
class GradientView: UIView {

    @IBInspectable var FirstColor: UIColor.clear{
        didSet {
            updateView ()
        }
    }
    @IBInspectable var SecondColor: UIColor.clear{
        didSet {
            updateView ()
        }
    }

    @IBInspectable var ThirdColor: UIColor.clear{
        didSet {
            updateView ()
        }
        func updateView() {

        }
    }
}

enter image description here


Solution

  • Should be like this:

    import UIKit
    
    @IBDesignable
    class GradientView: UIView {
        @IBInspectable var FirstColor: UIColor = .clear {
            didSet {
                updateView()
            }
        }
    
        @IBInspectable var SecondColor: UIColor = .clear {
            didSet {
                updateView()
            }
        }
    
        @IBInspectable var ThirdColor: UIColor = .clear {
            didSet {
                updateView()
            }
        }
    
        func updateView() {
    
        }
    }