End Google Ads 201810 - BS.net 01 --> I thought I would show you guys a quick tutorial on how to build native cocoa apps using C# and MonoMac. I will be showing you how to make the famous "Hello World" app.

Lets Begin!

You will need the following:
MonoDevelop IDE
MonoDevelop Framework SDK
XCode 4.x

One you have those, open up MonoDevelop. Click on "new solution" Drop down the C# category and select "Mac (open source)" and create a MonoMac project.

Now once that is done you should have some files and folders. Double click the Main********xib file and XCode should open. Add a button and a label. Now click the middle button above Editor in the top right of XCode. Find "Automatic" and click on it and go to "MainWindowController.h" Now right click and drag the button to the code and add an outlet called "guiButton" or whatever you want. Do the same with the label. Now right click and drag from the button again but this time select action and name it "buttonClicked."

Ok, that's done. Save and close XCode. Now go back to MonoDevelop and open Main********designer. A bunch of new code should have been added. Verify that the outlets and action have been added before continuing.
Your file should look like this:

// WARNING//// This file has been generated automatically by MonoDevelop to store outlets and// actions made in the Xcode designer. If it is removed, they will be lost.// Manual changes to this file may not be handled correctly.//using MonoMac.Foundation; namespace dontgivemeerrors{ [Register ("MainWindowController")] partial class MainWindowController { [Outlet] MonoMac.AppKit.NSTextField guiTextField { get; set; } [Outlet] MonoMac.AppKit.NSButton guiButton { get; set; } [Action ("buttonClicked:")] partial void buttonClicked (MonoMac.Foundation.NSObject sender); void ReleaseDesignerOutlets () { if (guiTextField != null) { guiTextField.Dispose (); guiTextField = null; } if (guiButton != null) { guiButton.Dispose (); guiButton = null; } } } [Register ("MainWindow")] partial class MainWindow { void ReleaseDesignerOutlets () { } }}
Ok, now open MainWindowController.cs and find "#endregion" Go under it and add the following line of code:

partial void buttonClicked (MonoMac.Foundation.NSObject sender){ }
Replace "buttonClicked" with name of your action. Now for the final step. Add this to that line of code:

partial void buttonClicked (MonoMac.Foundation.NSObject sender){ this.guiLabel.StringValue = "Hello World";}
Now run the app by pressing the icon with 2 gears and a green gear on the top right of MonoDevelop. Press the button and the label text should change to "Hello World."

Thats it. Most of your code will be under the action void. To find your .app file, go to YourUserName -> Projects -> NameOfProject -> NameOfProject -> bin -> Debug

Happy Coding!

- Team HsM
HSM