CGRect: origin property
The origin property is the rectangle's top-left corner, of type CGPoint. It is the same set of numbers as the rectangle's x and y fields.
Value
A CGPoint, equal to (x, y).
- Read-only; assigning to it throws
TypeError. - Each read gives a new
CGPoint, sor.origin === r.originisfalse. origindoesn'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.origin));
console.log(r.origin === r.origin);Result: It prints CGPoint(10, 20), then false.
Corresponding iOS API
CGRect.origin. ObjC has only the nested form; here both exist: rect.origin.x and rect.x read the same number.