Question

I would like to create a portable library for iPhone, that also could be used for other platforms.

My question is the fallowing:

Does anyone knows what is the best to be used on the iPhone: Objective-C or Objective-C++? Does it works with C++ the same way as Objective-C with C or not?

Reasons: Objective-C is a superset of C, but Objective-C++ is not a superset of C++.

Thanks in advance!

UPDATE: What about memory usage, speed in the same implementation of an use case?

UPDATE1: If anyone can provide any more information, he'll be welcome.

Was it helpful?

Solution

They're not really different languages. Objective-C++ is just Objective-C with slightly limited support for including C++ code. Objective-C is the standard dialect, but if you need to work with C++, there's no reason not to use it. AFAIK, the biggest practical difference (aside from allowing use of different libraries) is that Objective-C++ seems to compile a bit slower. Just be sure to read up on it first if you do decide to go that route, because the merging of C++ and Objective-C is not 100% seamless.

OTHER TIPS

If you're writing a portable library, and don't need specific language features for it, why not write it in straight C? It can be easily called from C++, C, Objective-C, and many, many other languages.

If you require specific language features that aren't available in C, you should tell us what they are so you can get better advice =)

I believe your information is incorrect. Objective-C++ is a superset of C++. Any C++ is legal Objective-C++. In addition, you can mix Objective-C and C++ code in an Objective-C++ (usually .mm) file and (with some restrictions) mix Objective-C and C++ class instance variables within an Objective-C++ class. Objective-C++ is particularly useful for interfacing between Objective-C and a C++ library. Write your cross-platform library in C++. You can then call it from Objective-C++ within an application. Re-read the Objective-C++ section of the Objective-C language guide for more info.

The major downside to using Objective-C++ is increased compile times (Objective-C++ is even worse than C++ and the Clang LLVM compiler doesn't handle Objective-C++ yet). There is no performance difference between Objective-C and Objective-C++ beyond any differences in the code that's called (e.g. if you're a better C++ dev., your C++ will probably be more efficient than your C library and visa versa).

If you are going to use this library on platforms other than the iPhone and Mac OS, you should use C++. If you plan only to port it to Mac OS, then go ahead and use Objective-C. Objective-C++ is just a way to integrate existing C++ code into Objective-C projects. Thus, you would not write a library in it. You might, however, use Objective-C++ to use this library from an iPhone or Mac project.

The truth is you can use C or C++ in Xcode. The reason to use Objective C for Cocoa and Cocoa Touch (iphone) is because of it's ease of use and how it handles many of the memory issues you would come across on it's own. Objective C and Xcode work like a dream. I would also recommend checking out http://www.kevincallahan.org/software/accessorizer.html Accessorizer is amazing and cuts development time into nothing.

Having said that I see no problem in writing functions/methods in C or C++ and using them within a part of your XCode project. Just do not expect to use Objective C to play as nicely on other platforms. Apple and Windows development IDE's are different and Microsoft has a nice habit for not making things as compatible with other environments (not just Apple.)

I am glad to hear someone out their trying to reuse their code for other projects : ) Too many people forget to create their own libraries these days and I haven't the slightest idea why.

I hope this helps. Cheers, Matthew

Here is your caveat: Spend the hundred on becoming a developer and launch xcode the IDE you will be working with on the Mac - this would be the best way for you to decide as it is apparent that you do not fully understand how this platform works at all.

Please don't be rude to everyone trying to help you. This community is built on respect. The people here really actually do help out and care and there are few places like this on the net left.

Go for C or C++ - I do not see any reason for recommending one over the other without knowing more about your goals.

In terms of memory usage, C++ and C do demand more disciplined coding. In terms of speed, C and C++ will in virtually any case be faster than any ObjC/ObjC++ solution. I do frequently mix my Objective C applications with C and C++ code and was always pleased with the results. As Jonathan correctly stated, ObjectiveC++ is mostly a bridge for using C++ code/libraries within your Objective C application/s.

You can freely use C++ objects from within Objective C++. You can however NOT use Objective C/C++ objects within C++. So its a one-way-road. To overcome any limitations imposed by this restriction, simply wrap your C++ objects with Objective C++ classes where needed.

"Objective-C is a strict superset of C, and Objective-C++ is a strict superset of C++." - https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html

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