CGRect: size property
The size property is the rectangle's size, of type CGSize. It is the same set of numbers as the rectangle's width and height fields.
Value
A CGSize, equal to (width, height).
- Read-only; assigning to it throws
TypeError. - Each read gives a new
CGSize, sor.size === r.sizeisfalse. sizedoesn't appear in the output ofJSON.stringify; the JSON has only the four fieldsx,y,width, andheight.- Where a rectangle is accepted on write, a plain object is recognized only by the four direct fields. A shape like
{ origin, size }isn't accepted and throws as "missing fields"; see Structs.
Examples
js
const r = new CGRect(10, 20, 100, 50);
console.log(String(r.size));
console.log(r.size === r.size);Result: It prints CGSize(100, 50), then false.
Corresponding iOS API
CGRect.size. ObjC has only the nested form; here both exist: rect.size.width and rect.width read the same number.