Windows Developer moving to macOS – please help me to start

Hello Everyone

This is my first post in the Apple Developer Forums.

I am a long time Windows developer – using C++ and the Win32 API (and Direct2D, Direct3D).

I want to start developing a desktop app for Mac (both for Intel and M1/2 processors).

And I don’t know where to begin… which is why I am posting here.

My criteria:

  1. I want to use C++ as much as possible. This is my strength and I have existing Windows apps that I would like to try to port. I realise that I might have to use some Objective C or Swift – but I hope this will be minimal (or that I can call into it from C++). Is it even possible to mainly use C++ in macOS?

  2. I don’t want to use a third-party GUI framework if possible. I prefer to use a macOS GUI API (if there is one). Is this possible?

  3. I am very familiar with Visual Studio., but I am happy to use XCode. Is this the best choice?

I realise that I am at the start of a very long learning curve. I hope that my (many years of) experience with Windows GUI programming will at least help me a little.

Thank you in advance for any help!

Best regards

AW

Answered by darkpaw in 726882022

I haven't ever written any C++ on the Mac, but I think you can write it in Xcode.

To be honest, though you might have strengths in Windows GUI programming, mainly just the ideas of how GUIs work on an OS is useful. You should prepare yourself for learning how things work on the Mac. We have UIKit, but that's Objective-C and Swift.

You might find it handy to start writing stuff in Objective-C or Swift and see how that works out for you. Swift is going to be supported going forward (and Objective-C for a good long time yet).

Check out some of the sample code projects on Apple's website (look for the WWDC 2022 stuff). You can gain a lot of knowledge by trying their stuff out and changing things to see how things work. Good luck.

Accepted Answer

I haven't ever written any C++ on the Mac, but I think you can write it in Xcode.

To be honest, though you might have strengths in Windows GUI programming, mainly just the ideas of how GUIs work on an OS is useful. You should prepare yourself for learning how things work on the Mac. We have UIKit, but that's Objective-C and Swift.

You might find it handy to start writing stuff in Objective-C or Swift and see how that works out for you. Swift is going to be supported going forward (and Objective-C for a good long time yet).

Check out some of the sample code projects on Apple's website (look for the WWDC 2022 stuff). You can gain a lot of knowledge by trying their stuff out and changing things to see how things work. Good luck.

You certainly can use C++ in macOS apps. By default, Xcode will compile files with a .m extension as Objective C, and with a .mm extension as Objective C++. You can also select individual files in your project and tell Xcode to use a different compiler than the default, but I'd advise against this. However, you'll notice that nearly all current Apple sample code is in Swift. Most of the hints and tips you'll find on the Internet will be for Swift. Any samples in Objective C are often out of date. It isn't impossible to figure out what to do, but it is an additional hurdle.

There is a macOS GUI API, it is called AppKit for macOS. There's another similar one for iOS called UIKit. Again, you'll find the majority of posts on Apple programming are for iOS and UIKit, because there are far more phones out there than desktops.

You can call into AppKit from ObjC or ObjC++ or Swift. If you have cross-platform library code written in C++ you can use that in a Swift or ObjC/C++ app, but you'll need to give it a C interface.

I don't think VS code can generate a macOS app (it can generate an iOS app), but I could be wrong. You can certainly run VS for Mac on your Mac, and use its editor if you're more comfortable with that. You can run Xcode from the command line if you want to fire off a build from VS, but Xcode integrates a debugger and I don't know how that would work in VSCode (for a macOS app).

A lot of the work in producing a shippable app isn't in the code itself, it is in localization, testing, packaging, signing and notarizing. Xcode can help with that.

Swift was introduced in 2014, it is quite mature now. If I were starting something brand new for macOS, I'd certainly write it in Swift.

If you're used to one platform and move to another, you'll find many things are different. The platforms are different, the user expectations are different and the tools and frameworks are different. Embrace that.

You can certainly use C++, in XCode, for macOS (or iOS) development. My current project is 85% C++, 15% objC++.

Before Swift, it was really very easy to combine C++ with objective-C in the same file - they refer to that as "objective C++". But that's not possible with Swift. You can combine Swift with C++ in the same project, in different source files, but I think you need to use only C semantics where they communicate.

The best approach will depend on the nature of the app you want to make. To port from Windows, you'll probably be able to keep the non-UI code unchanged in C++, but you'll need to completely re-write the UI.

If you have the patience, it may be best to start by ignoring the C++ aspect and learn how to build a GUI using SwiftUI. Do a few tutorials, until you understand what is possible and are getting familiar with the terminology etc. Then, think about how you might divide a project between the different languages.

At this point I don't think I'd recommend using much objC. Apple are introducing a few "Swift-only" APIs now. It could be more convenient than Swift in a few cases but they will be rare and it's another thing to learn.

Good luck!

Hi – thanks for the quick replies.

@darkpaw: Thanks – yes, I will look at the samples on Apple's website. I accept that I will have to learn either Swift or Objective C – but hopefully I can wrap them up and call them easily from C++.

@ssmith_c: Thanks. Ok, I didn’t know about Objective C++. That might well be the direction for me. So, AppKit is the Objective C API for GUI programming?

My issue is that I have a large app written for Windows in C++ which I want to port – hence my need for C++. It handles its own localization. I will definitely have to learn about packaging, signing and notarizing the Mac way.

I’ve just had a quick play with XCode writing a console app in C++. All seems fairly straight forward. Debug/Release, debugging, setting the C++ version etc. was all pretty quick with a few google searches.

I am happy (and expect) to learn new things. I have used a Mac for a long time (15+ years), so I understand (mostly) the ecosystem. I am just hoping to find a way to rewrite as little as possible for the port.

@endecotp: 85% C++, 15% objC++?? That is very encouraging!

Yes, I was expecting a GUI rewrite. I will definitely look at the Swift UI examples. As you say, this is my best place to start. Creating my own GUI framework was the first thing I did in the Windows version (by that, I mean my own C++ classes which wrapped up the Win32 and other APIs). Maybe I can do a similar thing on macOS by (eventually) writing C++ classes that wrap up calls to Swift.

I don’t know yet – I need to look at Swift and the AppKit first.

Thanks to everyone for all your help.

Best regards

AW

Instead of looking to call Swift from C++ you should probably look at it the other way round. Use Swift as the main language for your development - it integrates beautifully with Interface Builder and is ideally suited for building a gui. You can then make calls to C/C++/Obj-C using the Swift bridging interfaces.

Admittedly there is a bit to learn but I think you'll find Swift to be quite easy to become familiar with. I have found C/C++ to be very useful in Swift applications for dealing with Posix/System interfaces, then passing results back to Swift either as arguments or via closure/callbacks.

@granada29:

Thanks. That could well be the right way to go. Over the next few days I will be looking at Swift and try to learn how this all fits together. Big job!

Windows Developer moving to macOS – please help me to start
 
 
Q