You would do it the same way as any other function that you would write in C. So, if you have your function defined in a source file named myLibraryFunctions.m
, anyone who wanted to use that function would include the header file where you define it (probably myLibraryFunctions.h
, and then just make sure that they link with the object file (most of this will be done for you in Xcode if you simply create a file to house your "global" functions and include the header file for them in any source file that you access it from. Then just define it:
void analyzeThis(id anyObject);
void analyzeThis(id anyObject) {
NSLog(@"Object %p: %zu, %@", anyObject, malloc_size(anyObject), anyObject);
}
But in reality, you would write whatever you wanted in your function. These functions don't have to be a part of any class definitions or anything like that. In this case, they're exactly the same as they would be in C.