Question

We can define an C function as inline. But how about Obj-C methods? Can I make a method "inline"ed?

Was it helpful?

Solution

Objective C methods cannot ever be inlined, unfortunately.

There are lots of things which can affect which method will be invoked when a message is sent, and it can change at runtime, so inlining just isn't possible. Java has "final" to mitigate this issue but Objective C does not have a direct equivalent. Instead, you can use plain C functions in time-critical situations to dodge the issue.

OTHER TIPS

No, Objective-C methods cannot.

C functions however, can be.

Objective-c offers a handy #define in coreGraphics.h so you can use it to adapt something similar

#if !defined(CG_INLINE)
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#  define CG_INLINE static inline
# elif defined(__cplusplus)
#  define CG_INLINE static inline
# elif defined(__GNUC__)
#  define CG_INLINE static __inline__
# else
#  define CG_INLINE static    
# endif 
#endif

so your inline function will look like this:

CG_INLINE void doWork(...) { }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top