gpt4 book ai didi

swift - 结构是文件私有(private)的,不能从 swift 4.1 中的默认参数值引用

转载 作者:搜寻专家 更新时间:2023-11-01 06:01:07 25 4
gpt4 key购买 nike

我正在使用一个带有默认值的结构,就像这样。

 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)
}
}
}

我有一个方法可以将这些结构值作为默认参数传递。但在 swift4 中它不起作用。

 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) {

}

请查看总码here .

解决这个问题的方法是什么?

谢谢你...

最佳答案

有两个修复,如下所述,

1)DropdownAlert 中取出 Defaults struct 并使其成为 public甚至 properties 也因为你想在方法签名中传递它们,如下所示,

public struct Defaults {
public static var BackgroundColor = UIColor.white
public static var TextColor = UIColor.black
public static var Title = "Default Title"
}

class func showWithAnimation(_ animationType: AnimationType = .basic(timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)),
title: String = Defaults.Title,
message: String = Defaults.Message) {
}

2)Defaults 保留在 DropdownAlert 中,但使其成为 public 包括 properties还。并按如下方式访问,

class func showWithAnimation(_ animationType: AnimationType = .basic(timingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)),
title: String = DropdownAlert.Defaults.Title,
message: String = DropdownAlert.Defaults.Message) {
}

关于swift - 结构是文件私有(private)的,不能从 swift 4.1 中的默认参数值引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50342916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com