gpt4 book ai didi

swift - 遗留构造函数违规 : Swift constructors are preferred over legacy convenience functions. (legacy_constructor)

转载 作者:IT王子 更新时间:2023-10-29 05:49:55 41 4
gpt4 key购买 nike

我得到一个 SwiftLint此行警告:

return UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset)

这是警告:

Legacy Constructor Violation: Swift constructors are preferred over legacy convenience functions. (legacy_constructor)

我也在这一行收到警告:

return CGRectInset(bounds, insetX, insetY)

Legacy CGGeometry Functions Violation: Struct extension properties and methods are preferred over legacy functions (legacy_cggeometry_functions)

UIEdgeInsetsMakeCGRectInset 的 Swift 版本是什么?

最佳答案

Swift 希望您更新这些类型的新结构初始值设定项,而不是旧的 C 构造函数。因此,您的插入初始化程序将更改为:

return UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)

CGRectInset C 方法已更改为 CGRect 结构上的方法。

return bounds.insetBy(dx: insetX, dy: insetY)

关于swift - 遗留构造函数违规 : Swift constructors are preferred over legacy convenience functions. (legacy_constructor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39663734/

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