1

I am getting a "cannot use instance member 'appearance' within property initializer; property initializers run before 'self' is available". Please do not suggest to remove appearance from the code, that will not work. I also added a self.appearence.kcirclebackround and got and error as well.

Here is where the kCircleHeightBackground cgfloat is set `open class SCLAlertView: UIViewController {

public struct SCLAppearance {
    let kDefaultShadowOpacity: CGFloat
    let kCircleHeightBackground: CGFloat 
    let kCircleTopPosition: CGFloat
    let kCircleBackgroundTopPosition: CGFloat
    let kCircleHeight: CGFloat
    let kCircleIconHeight: CGFloat
    let kTitleTop:CGFloat
    let kTitleHeight:CGFloat
    let kWindowWidth: CGFloat
    var kWindowHeight: CGFloat
    var kTextHeight: CGFloat
    let kTextFieldHeight: CGFloat
    let kTextViewdHeight: CGFloat
    let kButtonHeight: CGFloat
    let contentViewColor: UIColor
    let contentViewBorderColor: UIColor
    let titleColor: UIColor

`

and then i'm getting an error at "appearance.kCircleHeightBackground"

var appearance: SCLAppearance!

// UI Colour
var viewColor = UIColor()

// UI Options
open var iconTintColor: UIColor?
open var customSubview : UIView?



// Members declaration
var baseView = UIView()
var labelTitle = UILabel()
var viewText = UITextView()
var contentView = UIView()
// "I get an error here at appearance.kCircleHeightBackground"__________var circleBG = UIView(frame:CGRect(x:0, y:0, width: appearance.kCircleHeightBackground, height: appearance.kCircleHeightBackground))
var circleView = UIView()
var circleIconView : UIView?
var duration: TimeInterval!
var durationStatusTimer: Timer!
var durationTimer: Timer!
var dismissBlock : DismissBlock?
fileprivate var inputs = [UITextField]()
fileprivate var input = [UITextView]()
internal var buttons = [SCLButton]()
fileprivate var selfReference: SCLAlertView?

public init(appearance: SCLAppearance) {
    self.appearance = appearance
    super.init(nibName:nil, bundle:nil)
    setup()
}

Image of error i get

ahmed
  • 115
  • 9

1 Answers1

0

As the error mentions, you are not able to use your appearance property until it has been set in the initializer. Your properties are evaluated before the initializer runs, so your only option here is to move the desired customisation of your circleBG view into the initializer, for example your setup()-method.

Jonas W
  • 585
  • 4
  • 11