CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero Is Unavailable In Swift
Answer :
CGRect Can be simply created using an instance of a CGPoint or CGSize, thats given below.
let rect = CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: 100, height: 100)) // Or let rect = CGRect(origin: .zero, size: CGSize(width: 100, height: 100)) Or if we want to specify each value in CGFloat or Double or Int, we can use this method.
let rect = CGRect(x: 0, y: 0, width: 100, height: 100) // CGFloat, Double, Int CGPoint Can be created like this.
let point = CGPoint(x: 0,y :0) // CGFloat, Double, Int CGSize Can be created like this.
let size = CGSize(width: 100, height: 100) // CGFloat, Double, Int Also size and point with 0 as the values, it can be done like this.
let size = CGSize.zero // width = 0, height = 0 let point = CGPoint.zero // x = 0, y = 0, equal to CGPointZero let rect = CGRect.zero // equal to CGRectZero CGRectZero & CGPointZero replaced with CGRect.zero & CGPoint.zero in Swift 3.0.
Quick fix for CGRectMake , CGPointMake, CGSizeMake in Swift3 & iOS10
Add these extensions :
extension CGRect{ init(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) { self.init(x:x,y:y,width:width,height:height) } } extension CGSize{ init(_ width:CGFloat,_ height:CGFloat) { self.init(width:width,height:height) } } extension CGPoint{ init(_ x:CGFloat,_ y:CGFloat) { self.init(x:x,y:y) } } Then go to "Find and Replace in Workspace" Find CGRectMake , CGPointMake, CGSizeMake and Replace them with CGRect , CGPoint, CGSize
These steps might save all the time as Xcode right now doesn't give us quick conversion from Swift 2+ to Swift 3
In Swift 3, you can simply use CGPoint.zero or CGRect.zero in place of CGRectZero or CGPointZero.
However, in Swift 4, CGRect.zero and 'CGPoint.zero' will work
Comments
Post a Comment