Duck
Duck

Reputation: 35933

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?

Upvotes: 5

Views: 2217

Answers (2)

DawnSong
DawnSong

Reputation: 5152

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.

Upvotes: 1

Droppy
Droppy

Reputation: 9721

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));
}

Upvotes: 9

Related Questions