Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode complains about Unused functions that are used

I have a "MyConstants.h" file that is imported by several classes.

Inside that file I have things like:

static BOOL isIndexValid(NSInteger index) {
  return ((index >=0) && (index < 200));
}

This function is extensively used by the classes importing MyConstants.h. Even so, Xcode complains that this function and others are not used.

Why?

like image 279
Duck Avatar asked Jan 05 '23 15:01

Duck


1 Answers

Defining a static function (or variable, for that matter) in a header file means every source file that imports that header file will get its own copy.

That is not good and is what the compiler is complaining about (not every source file references this function).

Make it static inline instead:

static inline BOOL isIndexValid(NSInteger index) {
  return ((index >=0) && (index < 200));
}
like image 147
Droppy Avatar answered Jan 18 '23 20:01

Droppy