xcode Legacy Constructor Violation:Swift 构造函数比遗留的便利函数更受欢迎。(legacy_constructor)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39663734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Legacy Constructor Violation: Swift constructors are preferred over legacy convenience functions. (legacy_constructor)
提问by etayluz
I'm getting a SwiftLintwarning on this line:
我在这一行收到SwiftLint警告:
return UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset)
This is the warning :
这是警告:
Legacy Constructor Violation: Swift constructors are preferred over legacy convenience functions. (legacy_constructor)
Legacy Constructor Violation:Swift 构造函数比遗留的便利函数更受欢迎。(legacy_constructor)
I'm getting a warning on this line as well:
我也在这条线上收到警告:
return CGRectInset(bounds, insetX, insetY)
Legacy CGGeometry Functions Violation: Struct extension properties and methods are preferred over legacy functions (legacy_cggeometry_functions)
遗留 CGGeometry 函数违规:结构扩展属性和方法优于遗留函数(legacy_cggeometry_functions)
What is the Swift version for UIEdgeInsetsMake
and CGRectInset
?
UIEdgeInsetsMake
和的 Swift 版本是CGRectInset
什么?
回答by keithbhunter
Swift wants you to update to the new struct initializers for those types, instead of the old C constructors. So your inset initializer would be changed to this:
Swift 希望你更新这些类型的新结构初始化器,而不是旧的 C 构造器。因此,您的插入初始化程序将更改为:
return UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
The CGRectInset
C method was changed to be a method on the CGRect
struct.
在CGRectInset
C法改变为是对一个方法CGRect
结构。
return bounds.insetBy(dx: insetX, dy: insetY)