Utilizing C++ in iOS and MAC Os X Applications

Utilizing C++ in iOS and Mac OS X applications

Short answer, yes.

For pure C++, you should take a look at the QT framework.

Otherwise, you'll have hard time for the UI part.

But also remember that Objective-C can be mixed with C++.

That's called Objective-C++ (.mm files).

You can then write code that mix C++ and Objective-C code.
With this, you can have the UI parts in Objective-C (may be better, as it will use the native frameworks for the UI components), and the other things in C++.

If you've decided to learn Objective-C, but still want to code in C++ for some parts, I would recommend this approach, instead of pure C++.

On iOS, this is also the only way. While you can code in C++, you have to use Objective-C for the UI part.

EDIT

Here are a few links to get started with Objective-C++:

  • Strategies for Using C++ in Objective-C Projects
  • From C++ to Objective-C
  • CocoaDev

Utilizing resources of separate apps on OS X

It's still rather up to what each app will let you do, rather than just being able to do anything, but take a look at OS X's scripting/automation abilities. Primarily this is accessed through AppleScript, but there's now a JavaScript frontend as well (new to Yosemite).

If you're looking at building a native application that takes advantage of other applications, the same scripting abilities can also be reached via the Scripting Bridge from Cocoa (Objective-C/Swift).

Creating window application in pure c on mac osx

You can use Objective-C runtime API example (iOS) Creating an iOS app in pure C

Alternative the same code in obj-c :

echo '#import <Cocoa/Cocoa.h>
int main ()
{
@autoreleasepool{
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
id applicationName = [[NSProcessInfo processInfo] processName];
id window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 120, 120)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window setTitle: applicationName];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
}
return 0;
}' | gcc -fobjc-arc -framework Cocoa -x objective-c -o MicroApp - ; ./MicroApp

This will run Cocoa app with 1 window. Like on screenshot below

Sample Image

You can actually add menu using NSMenu

    id applicationMenuBar = [NSMenu new];
id appMenuItem = [NSMenuItem new];
[applicationMenuBar addItem:appMenuItem];
[NSApp setMainMenu: applicationMenuBar];

Complete solution for writing Mac OS X application in C++

If you want to use C++ instead of Objective-C, and still want to avoid an intermediate layer of libraries (such as QT), you can use Carbon.

I would use XCode instead of Eclipse simply because Eclipse is way slower when dealing with hardcore C/C++ programming (compiling, debugging, testing).

When I first started to program in Mac OS X, I was in the same page you are now. I thought it was better to stick to the language I knew (C++) and use an older library (Carbon). For some reason I don't remember now, I forced myself into Cocoa (Objective-C). Looking back, I think it was a good thing because:

  1. Objective-C is not fundamentally different to C++
  2. Cocoa is better, faster and simpler than Carbon
  3. iPhone Dev is exclusively Cocoa (Carbon is not supported)

Difference between iPhone development and Mac OSX development

  1. Many different UI elements and interactions.
  2. The same.
  3. Different.
  4. IMHO yes.

You may want to check out these posts to help you transition:

Jumping from iOS to OSX

Removing iOS SDKs from OSX

How can I run a C program on Mac OS X using Terminal?

First save your program as program.c.

Now you need the compiler, so you need to go to App Store and install Xcode which is Apple's compiler and development tools. How can you find App Store? Do a "Spotlight Search" by typing Space and start typing App Store and hit Enter when it guesses correctly.

App Store looks like this:

Sample Image

Xcode looks like this on App Store:

Sample Image

Then you need to install the command-line tools in Terminal. How can you start Terminal? You need to do another "Spotlight Search", which means you type Space and start typing Terminal and hit Enter when it guesses Terminal.

Now install the command-line tools like this:

xcode-select --install

Then you can compile your code with by simply running gcc as in the next line without having to fire up the big, ugly software development GUI called Xcode:

gcc -Wall -o program program.c

Note: On newer versions of OS X, you would use clang instead of gcc, like this:

clang program.c -o program

Then you can run it with:

./program
Hello, World!

If your program is C++, you'll probably want to use one of these commands:

clang++ -o program program.cpp
g++ -std=c++11 -o program program.cpp
g++-7 -std=c++11 -o program program.cpp

Does one need an XCode to develop iOS apps using C++ on Visual Studio?

The IDEs required to develop iOS Applications (Xcode, AppCode) are only available for Mac OS. So you would need to install a hackintosh version of Mac OS on your PC and start developing Apps and when you are ready with your App, you can buy a Mac and legitimately submit to the App-Store.

Please refer to this link for more information: iPhone Development on Hackintosh

Apart from Objective-C, which languages can I use when developing for Mac OS and iOS?

You can use c and c++ but you can't make any application without using objective - c. Since you need to use native app controllers and libraries.

Also in starting you find it difficult to learn obj-c because of it's syntaxes but after using them you are going to love it. So don't be scared and learn obj-c.

You can use some frameworks (e.g aapcelerator, phone gap)
but they are unable to give result like native app.



Related Topics



Leave a reply



Submit