Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm getting a SwiftLint warning on this line:

return UIEdgeInsetsMake(topInset, leftInset, bottomInset, rightInset)

This is the warning :

Legacy Constructor Violation: Swift constructors are preferred over legacy convenience functions. (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)

What is the Swift version for UIEdgeInsetsMake and CGRectInset ?

like image 667
etayluz Avatar asked Sep 23 '16 14:09

etayluz


1 Answers

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:

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

The CGRectInset C method was changed to be a method on the CGRect struct.

return bounds.insetBy(dx: insetX, dy: insetY)
like image 111
keithbhunter Avatar answered Sep 28 '22 03:09

keithbhunter