How can I declare a global variable in Xcode and its data type should be integer and accessible by every class.
Share
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.
In some very special cases a truly global variable can simplify things. I don’t think you researched the problem exhaustively, but here is my answer anyway, a simple case:
Now, you can use
globalVariableanywhere in your code, you don’t even need to include the header file.Warning: things are slightly complex if you need thread safety or a different variable type.