Necesito poder verificar si ya he lanzado una variable en Object-c. Traté de verificación si se ha cambiado a nulo:¿Cómo puedo verificar si se lanza un objeto?
//Checks if buildview is null and returns respective output
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
//allocates memory and initalizes value
BuildView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
//Checks if buildview is null and returns respective output again
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
//Releases the view
[BuildView release];
//Checks if buildview is null and returns respective output again
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
Los resultados fueron los siguientes:
Build View Value (pointer): Null
Build View Value (pointer): Not Null
Build View Value (pointer): Not Null
¿Hay alguna forma más fácil comprobar si se cancela la asignación?
Lo que parece estar pidiendo no es si el objeto ha sido puesto en libertad, sino más bien si ha sido desasignado. – PengOne
posible duplicado de [¿Cómo determinar si tengo un puntero al objeto liberado?] (Http://stackoverflow.com/questions/12280799/how-to-determine-if-i-have-a-pointer-to-released -objeto) – OrangeDog