Is it safe to use [[self.view viewWithTag:999] removeFromSuperview]; without checking if the view actually exists?
There is no error on simulator but will it cause no problem on a real device?
Is there any drawback of not using such condition?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is completely alright to call
[[self.view viewWithTag:999] removeFromSuperview];directly. If the view exists then[self.view viewWithTag:999]will return the view and it will be removed from its superview. If the view doesn’t exists then[self.view viewWithTag:999]will returnniland passing any message to nil wont take any effect.So, in your case, there is no need to check whether the view actually exists or not.