CGSize(width: 360, height: 480) and CGSizeMake(360, 480) seem to have the same effect. Is one preferred to the other? What is the difference?
Overview. A CGSize structure is sometimes used to represent a distance vector, rather than a physical size. As a vector, its values can be negative. To normalize a CGRect structure so that its size is represented by positive values, call the CGRectStandardize(_:) function.
A structure that contains the location and dimensions of a rectangle.
The CGSize constructor is a Swift extension on CGSize:
extension CGSize {
public static var zero: CGSize { get }
public init(width: Int, height: Int)
public init(width: Double, height: Double)
}
CGSizeMake is a leftover inline function bridged from Objective-C:
/*** Definitions of inline functions. ***/
// ...
public func CGSizeMake(width: CGFloat, _ height: CGFloat) -> CGSize
Both have the same functionality in Swift, the CGSize constructor is just more "Swifty" than the other and provided as a convenience.
While as functionality they don't have any difference, CGSizeMake() is/will be deprecated. It is easier to write and read CGSize(), so Apple prefers you to use CGSize() for the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With