
class supClass: UIVIEw { let defaultFontSize: CGfloat = 12.0}class subClass: supClass { private func calcSomething(Font: UIFont = UIFont.systemFontOfSize(defaultFontSize)) { //... Do something }} 它出什么问题了?非常感谢
在类范围上计算方法参数的默认值,不是实例范围,如下例所示:
class MyClass { static var foo = "static foo" var foo = "instance foo" func calcSomething(x: String = foo) { print("x =",x) }} let obj = MyClass()obj.calcSomething() // x = static foo 如果没有静态var foo,它就不会编译.
适用于您的情况,这意味着您必须使用所使用的属性
作为默认值static:
class supClass: UIVIEw { static let defaultFontSize: CGfloat = 12.0 // <--- add `static` here}class subClass: supClass { private func calcSomething(Font: UIFont = UIFont.systemFontOfSize(defaultFontSize)) { //... Do something }} (请注意,无论是否在中定义了属性,都与此问题无关同一个班级或超级班.)
总结以上是内存溢出为你收集整理的Swift Instance成员不能用于类型全部内容,希望文章能够帮你解决Swift Instance成员不能用于类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)