We can define an C function as inline
. But how about Obj-C methods? Can I make a method "inline"ed?
Asked
Active
Viewed 1,508 times
1

jscs
- 63,694
- 13
- 151
- 195

Andrew Chang
- 1,289
- 1
- 18
- 38
-
1See also: [Does LLVM convert ObjC methods to inline functions?](http://stackoverflow.com/q/8194504) – jscs Feb 18 '14 at 03:01
-
1You cannot inline an Objective-C function. You can inline a standard C function. – Hot Licks Feb 18 '14 at 03:01
-
@BenPious Oops, yeah, duplicated. I searched but did not find it, therefore I raised a question by myself. – Andrew Chang Feb 18 '14 at 03:37
2 Answers
6
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.

StilesCrisis
- 15,972
- 4
- 39
- 62
3
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(...) { }

cream-corn
- 1,820
- 14
- 26