CGPoint property, how to determine is set or not

Discussion in 'iOS Programming' started by i.yalovecky, Mar 25, 2010.

  1. i.yalovecky macrumors member

    Feb 24, 2010
    With NSString all clear, if nil, so not set. But with CGPoint i not to get decision if only use CGPoint* and then use malloc and free, so if not set it will be nil to. In my program i have not untruth value for x and y.
    And second way to use NSValue, but i don't sure about memory efficiency. As i know IPhone has strong memory limitation.
  2. jnic macrumors 6502a

    Oct 24, 2008
    An uninitialised CGPoint will have x and y values set to zero.

    If you want something you can check for nil then wrap your CGPoint in an object, as you suggest. The memory impact will be negligible (you can use the ObjAlloc tool to confirm this).
  3. robbieduncan Moderator emeritus


    Jul 24, 2002
    The obvious downside is that (0,0) is a perfectly valid point in many uses. If you want to have an "unset" value to then choose a value that can never be valid and initialise your unset points to that.

    For most people a sensible value to choose would be CGFLOAT_MIN.

Share This Page