Pour vérifier si un chemin est NULL, utilisez l'opérateur ==
/!=
.
if (path != NULL)
CGPathAddLineToPoint(path, NULL, point.x, point.y);
Pour vérifier si un chemin ne contient pas de rien, utilisez CGPathIsEmpty.
if (!CGPathIsEmpty(path))
CGPathAddLineToPoint(path, NULL, point.x, point.y);
Pour vérifier si a été déplacé, utilisez CGPathGetCurrentPoint et comparer avec le point d'un chemin (0, 0).
if (!CGPointEqualToPoint(CGPathGetCurrentPoint(path), CGPointZero))
CGPathAddLineToPoint(path, NULL, point.x, point.y);
Bien sûr, cela ne peut pas distinguer entre un chemin vraiment vide et un chemin que quelqu'un a appelé CGPathMoveToPoint(path, NULL, 0, 0)
là-dessus.
(En fait, la raison pour laquelle vous avez besoin de prendre soin? Il suffit de créer un nouveau chemin si vous voulez un vide.)
mais il y a plusieurs façons d'écrire cela. beaucoup de gens choisissent aussi 'if (chemin)', 'if (chemin! = NULL)', et 'if (0! = chemin)' - ils produisent tous les mêmes résultats. – justin