Swift2与Swift3不同语法

由于Swift2与Swift3之间有好多语法修正,所以刚入学还是比较蛋疼。网上查了一些资料,罗表以下备用:

CGRect

Swift 2:

let frame = CGRectMake(0, 0, 20, 20)
Swift 3:

let frame = CGRect(x: 0, y: 0, width: 20, height: 20)
CGPoint

Swift 2:

let point = CGPointMake(0, 0)
Swift 3:

let point = CGPoint(x: 0, y: 0)
CGSize

Swift 2:

let size = CGSizeMake(20, 20)
Swift 3:

let size = CGSize(width: 20, height: 20)
CGRectGetMidX

Swift 2:

CGRectGetMidX(view)
Swift 3:

view.midX
CGRectGetMidY

Swift 2:

CGRectGetMidY(view)
Swift 3:

view.midY
UIColor

Swift 2:

let color = UIColor.redColor()
Swift 3:

let color = UIColor.red
“NS”

Swift 2:

NSTimer
NSData
NSError
Swift 3:

Timer
Data
Error
UserDefaults

Swift 2:

NSUserDefaults.standardUserDefaults().//something
Swift 3:

UserDefaults.standard.//something

Binary operator ‘*’ cannot be applied to operands of type ‘CGPoint’ and ‘CGFloat’

查看了CGPoint属性,也是使用的CGFloat,但就是会出错,如下图:
CGFloat

解决问题:
突然想到可以找QQ群问啊,于是找到了问题,是要在CGPoin中的X和Y轴各自计算就不会出错。

网友发来的帮助文档:CGPoint+Extensions.swift