Objective-C++ for iOS development - iphone

Is it possible to use Objective-C++ for iOS application (iPhone, iPad, iPod touch) development?
Are there any examples and source code on the Internet?

Using ObjC++ is quite easy.
You have to declare source files with extension .mm. It will make compiler treat them as ObjC++. The same with headers: use the .hh extension.
There is another option: go to target settings and set Compile Sources As to Objective-C++.
That's all. No additional work is necessary.
Some notes: if you want to develop a native iOS app, then use Objective C. It will save a lot of time.
But in some cases using C++ is more appropriate. E.g. for cross-platform development. So you use only a little bit of Objective C for iPhone or Java for Android just to glue your code with environment. Everything else in C++. I use this for my cross-platform game development.
Another case is performance: Objective C is principally slower then C++. However it is only noticeable during method calls (in ObjC it is called messaging).

Yes, you can. Take a look at the samples and new file templates that Apple provides.

Related

Is it possible to use some C source code in iPhone project?

I found a speech synthesizer that supports many languages (http://espeak.sourceforge.net/index.html). But the source code that is available is written in C.
What can i do to make it work on iPhone?
Objective-C is a strict super set of C. Which means you can use any C code in your Obj-C project.
Yes, as long as it's been ported to the LLVM C-compiler. You can create a statically linked framework out of it, and then link into your project.
Apple does not allow dynamically-loaded frameworks.

Using c/c++ library that uses network for iphone app objective c

I am currently evaluating if a c/c++ library may be used for a specific iPhone project of mine. The original library makes heavy use of windows specific code (for example it includes windows.h and winsock.h). I am aware that I will have to rewrite the parts that use windows specific code and replace winsocks with for example bsd sockets. Or try to convert to objective-c++ and use IOS specific networking apis as it's recommended in Apple's documentation.
But as it turns out in Apple's documentation, in iOS only C and Objective-C code is allowed for networking. "iOS supports networking code written in C and Objective-C." ( https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_Networking_iPhone/ )
That sounds like I have to rewrite the whole library in objective-c to make it work on IOS. Or would it be sufficient to programm a wrapper class in objective-c and work with the original (adapted to bsd sockets api or objective-c++) library? -> Using C/C++ static libraries from iPhone ObjectiveC Apps
But the actual networking code still would be written c/c++ not objective-c.
Is there any chance this might work? I don't want to do all the work of adapting the library and then notice that this approach does not work.
Has anyone tried something similiar before?
Best regards,
Mike
You should be able to rewrite portions of your C++ library to used BSD sockets instead of the Windows sockets API without any problems.
Apple does not forbid C++ code from accessing the network, however the only networking APIs offered by iOS are in either C (BSD sockets, CoreFundation) or Objective-C (Foundation…), perhaps that's the source of your confusion. You can freely mix C, C++ and Objective-C code in your own code or in statically linked libraries.

support iphone,ipad,android

develop android apps that should support iphone,ipad,android.is there any way for developing this kind of generic app or we need to develop aps depending on mobile os
Though it is possible to create an universal application for iphone and ipad i don't think you can do the same for Android.
In my opinion it is always better to port your application to Android based on your requirements so that you can take advantages of the API's that the platform is offering you.
You can try using a framework named Titanium Appcelrator. This framework will help you target iPhone, iPad, Android with the same code base. This also lets you access most of the Native hardware features available with these platforms but not all. It seems that this also may support Blackberry soon.
We are struggling with the same question at the moment. Since we are working for Android, Maemo, Meego, iPhone and Blackberry (+Symbian 3 soon), HTML5 looked promising, and we dedicated quite some time investigating it. The end result was HTML5 is not yet ready for the development we were hoping for. It's fine if you need simple functionality, but as soon as something more advanced is needed, you need to create a different version. Even if it suits your needs, every platform requires different HTML5-to-native bridge, and every platform has a different engine. As you can see, only front end part could be partially used.
In your case, you need two different applications, one for Android, another one for iPhone/iPad. Try to see if you could take advantage of HTML5, if not, you are unfortunately stuck with separate development for some time to come. Unless you will create a web app and use it with device's browser.
You can create common functionality libraries with C or C++ and use these libraries in iPhone/iPad and use Android's NDK tool to integrate theses libraries with Android
On Android, you're using Java as the main language, and you can also use C and C++ . On iOS, you're using Objective-C as the main language, and also can use C and C++. So the common denominator would be C (at least on the iPhone there are no C++ GUI classes). I have no idea about developing on Android, but on iPhone it's no fun to purely work in C (and I'm not sure if it's even possible, maybe it is but should I when working with Objective-C/Cocoa is fun).
What you can do is write generic logic and share that between both systems, like a library. For example, I worked on a project where we used a C++ SIP/VoIP library that also compiles and runs on Symbian. It shouldn't be a big problem to write C code that can be shared between iOS and Android, as long as it is mostly about logic and not about calling system-specific stuff (you can of course include system specific stuff and guard that with #ifdef but you don't want your library to have more system-specific than system-agnostic code, I guess). For example, if you intend to write a networked game you could implement the network protocol in a way that could be shared between iOS and Android.
But as soon as you're hitting the GUI level I don't think you can share any code, and even if you could you probably don't want to because if you use the native languages/IDEs you are faster designing the GUIs each in their respective main languages/IDEs than trying to find a common way and then have to live with compromises and trying to make it work on both systems all day long. Better to implement the GUI native to each platform (e.g. Xcode has a very good graphical tool called Interface Builder that can save a lot of work/typing).
we can go for the XML VM to run the android apps in iphone.
Check this for more info.
xmlvm.org

Is TA-lib.org support on iOS on iphone?

I would like to add Technical analysis support to my financial project on iphone. And I found TA-lib on www.ta-lib.org, this library supports many indicators I need.
I would like to ask: Can I use ta-lib on my iphone development? And how I can do it, because this library is written in C language? I knew that Cocoa can compile C but how I can do it, import this library to iOS?
Any help would be appreciated.
Thanks
The iPhone SDK tools will compile most portable C code just fine (C is a pure subset of Objective C). There appears to be C source code available for the library in which you're interested. If so, you could try just including the source to the library in your iPhone Xcode project, and see if it all compiles, which it might if there are no dependency or collision problems. You may or may not need the entire library, which might help simplify things (or not).
You could also compile a separate static library, and then include that library, and the headers, in your iPhone app; but that technique may be a bit more complicated that your requirements might indicate.

Is programming for Android completely different from programming for iPhone?

I have made apps for iPhone, but want to also code for the Android but want to know if it is first worth my time, second worth my having to learn another language, and third worth the effort in the sense that am I going to make a profit from this. Also if in any way Android code is similar, then will it be hard to bring the iOS (Xcode) files, or copy and paste my iOS code into the Android code.
It's a most definite no. As iPhone Guy pointed out, there's a major difference in the languages both platforms require. iPhone uses Objective-C whereas the Android is based on Java (don't know if it's Mobile Edition or "regular" though). In addition, it's a completely different set of APIs. iPhone uses a modified form of Cocoa called Cocoa Touch whereas the Android makes uses of Google's SDK for it. In answer to your question, you won't be able to copy/paste your code between the languages. Your Objective-C code won't compile to Java and vice versa.
Yes -- programming on the iPhone uses Objective-C while programming for Android is in Java. Although they use similar concepts, the two languages are different.
I was a Java programmer before switching to Objective C. Personally I like Objective C better than Java, but that's just a personal opinion ;)