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

    Joined:
    Feb 24, 2010
    #1
    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

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    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

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    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