I’m about to start writing a static library for an iOS application and got couple of questions
- Is it ok to use pure C++ inside the library and expose public classes that do have methods accepting std::vector and such?
- I’m coming from a strong typed programming world such as C++ and C# and is much more easy for me to use C++ for this library.
- In general, are pure iOS developers ok to use C++ code and change their .m files into .mm?
- In xCode can I have both static library and a demo project both loaded into same application so it would be easier to debug?
- How do I make a post-build step for the static library project so it copies the .a file to needed location?
- How do I debug the static library?
- In general, are static libraries a common stuff for iOS project, or everyone prefers source code to be embedded into their application?
Any articles or books about this are very welcome.
Thx
This is a lot of questions, but I have partial answers.
1) Not sure on this, as I don’t generally use Objective-C++, but the second part yes you can use C++ (the 1998 standard as of LLVM v3) and changing your extension to .mm will automatically let the compiler know that you want to compile it using Objective-C++.
2) The best way to do this is to create a project reference. Make a project out of your static library, then drag that project as a subproject of your other project.
3) See step 2, then add the .a file in your Link With Library section in Build Phases.
4) Since the source code will show up in your project, I assume you can simply place breakpoints but I’m not sure.
5) Yes, making libraries is very common. In fact it would be silly not to if you need to use the same code in more than one project.
I urge you to make a cross project reference, because otherwise I’m sure you will forget that you need to compile the static library for every build type (debug/release and simulator/device). Cross project referencing will take care of this for you.