Im using a struct with default values like this.
fileprivate struct Defaults {
static var BackgroundColor = UIColor.white
static var TextColor = UIColor.black
static var Title = "Default Title"
static var Message = "Default message!"
static var AnimationDuration: Double = 0.25
static var Duration: Double = 2
static var Height: CGFloat = 90
static var TitleFont: UIFont = UIFont(name: "SourceSansPro-Semibold", size: Defaults.FontSize)!
static var MessageFont: UIFont = UIFont(name: "SourceSansPro-Regular", size: Defaults.FontSize)!
static var FontSize: CGFloat = 14 {
didSet {
TitleFont = TitleFont.withSize(FontSize)
MessageFont = MessageFont.withSize(FontSize)
}
}
}
I have a method in which passing the these struct values as a default arguments. But in swift4 it's not working.
class func showWithAnimation(_ animationType: AnimationType = .basic(timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)),
title: String = Defaults.Title,
message: String = Defaults.Message,
backgroundColor: UIColor = Defaults.BackgroundColor,
textColor: UIColor = Defaults.TextColor,
duration: Double = Defaults.Duration) {
}
Please check the total code here.
What's the work around for this ?
Thankyou...
There are two fixes as stated below,
1) Take
Defaults
struct
out ofDropdownAlert
and make itpublic
evenproperties
also as you want to pass them in method signature as below,2) Keep
Defaults
insideDropdownAlert
but make itpublic
includingproperties
also. And access as below,