Why In Mailcore2 Sample the 'MCOMessageView' file is a c++ file instead of objective c one?

290 Views Asked by At

I'm checking the source code from mailcore 2 sample demo. The IOS project has a class 'MCOMessageView.mm'. It's a very good helper class with a webview and a few delegates for html rendering. So why use 'mm' as its file extension since it doesn't contain any c++ code.

2

There are 2 best solutions below

0
Florian Burel On BEST ANSWER

Some developers, used to deal with ObjC++, use the .mm extension by default for their ObjC class, even if no C++ code is needed, so that they can use ObjC++ later on if needed.

MailCore uses ObjC++ by default, so .mm extension for class by default even if at their is no C++ code in it at the time, it can be added in the future.

It as virtually no cost a run time, so it's.. just a way of doing things. And since LVVM, it has but little cost at build time

Another possibility is that their was C++ in a previous version of the file and, commit after commit, C++ code was replace and they didn't bother renaming the class because they can still add some C++ code in the future and they want to keep their hand free.

0
Dinh Viêt Hoà On

The reason for using .mm is that it will hint Xcode that it needs the C++ runtime to link the final binary. If I used .m, I would have to pass a flag explicitly.