Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a CGSize in Swift?

Tags:

swift

How can I create a CGSize in Swift? This is what I have tried so far (but doesn't work):

var s:CGSize = {10,20}
var s:CGSize = CGMakeSize(10,20)
like image 310
Shai UI Avatar asked Dec 28 '14 21:12

Shai UI


2 Answers

Your first attempt won't work because C structs don't exist in Swift. You need:

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

Or (before Swift 3 only, and even then, not preferred):

let size = CGSizeMake(20,30)

(Not MakeSize).

like image 113
jrturton Avatar answered Oct 17 '22 02:10

jrturton


As of Swift 3 you can no longer use CGSizeMake

The solution for Swift 3 is var size = CGSize(width: 20, height: 30)

like image 33
Wyetro Avatar answered Oct 17 '22 04:10

Wyetro