Xcode complains about Unused functions that are used

2k views Asked by At

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?

2

There are 2 answers

4
Droppy On BEST ANSWER

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));
}
1
DawnSong On

Try to insert __unused between return type and function name, and it works for me on Xcode 10.2

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

Hope it will be helpful for you.