I would like to initially set a CGPoint property to a particular point (middle of screen). Other methods may subsequently wish to change this property. My thoughts were to initi
A CGPoint
is a struct, so you can't set it to nil or NULL (it's not a pointer). In a sense, there's really no "uninitialized" state. Perhaps you could use {0.0, 0.0}
to designate an unset CGPoint
, but that's also a valid coordinate. Or you could use negative x
and y
values to flag an "uninitialized" point, since negative values can't be valid drawing points, but that's a bit of a hack, too.
Probably your best bet is to do one of two things:
CGPoint
. This value can be set to NULL
when uninitialized. Of course, you have to worry about malloc
ing and free
ing the value.Store the CGPoint
alongside a BOOL
called pointInitialized
or somesuch, initially set to NO
, but set to YES
once the point has been initialized. You can even wrap that up in a struct:
struct {
CGPoint point;
BOOL initialized;
} pointData;