In the Master-Detail Xcode template, where do I define a function such that it is globally accessible (by all UIViewControllers and their subclasses)?
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.
If you have some code that doesn’t care what class of object calls it, it could probably be encapsulated into a function or subroutine instead of a method.
A method is a special type of function or subroutine that knows about an object and its class. A function or subroutine is like a global method that doesn’t.
Added:
Objective C is a superset of the C programming language. So C functions and subroutines are the same in both languages. You can write one in a (or any) .c or .m file, and declare it in a .h file to be included wherever you want it used. Pass it parameters as needed and get a return value from functions, just like methods (except for being unrelated to any inherent class of object).
Added #2: But since you want your method to know about some NSStreams, then it should probably be a method of some Model class (MVC paradigm) containing those streams, and not truly global. Pass this Model object to any view controllers or other classes that need to access it.