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?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
So in case if you are talking about the difference on usability aspect then there is no basic difference between
CGSize()
andCGSizeMake()
.But if you are talking about structural and programatic difference between this twos then here is some code snippet structure and explanation as well.
CGSize()
CGSizeMake()
Explanation:-
On the first case here i.e.
CGSize()
, the code clearly demonstrates that its a structure which generally takes height and width asCGFloat()
and represent a distance vector but not a physical size. As a vector the value could be negative.On another hand in case of
CGSizeMake()
, we can easily understand that its a function rather than a structure. It generally takes height and width asCGFloat()
and returns aCGSize()
structure.Example:-
CGSize()
CGSizeMake()
Now in case of pure swift usage and code
CGSize()
is much simpler and understandable thanCGSizeMake()
. You can get that from the above example right..!!!!Thanks,
Hope This Helped.
While as functionality they don't have any difference,
CGSizeMake()
is/will be deprecated. It is easier to write and readCGSize()
, so Apple prefers you to useCGSize()
for the future.The
CGSize
constructor is a Swift extension onCGSize
:CGSizeMake
is a leftover inline function bridged from Objective-C:Both have the same functionality in Swift, the
CGSize
constructor is just more "Swifty" than the other and provided as a convenience.