How Set up project to use Cocoa in Juce?

Hi I’d like to make the iOS user interface of my app with swift, so I add in my Xcode project a swift files that inherit ViewController class and I generated also the " - App-Bridging-Header.h" and a xib file to create the gui.

at this point in a file called MainWindow.mm I wrote this code:

#import <UIKit/UIKit.h>

#include "../JuceLibraryCode/JuceHeader.h"

#include "MainWindow.h"

#include "MainViewController.swift"

MainWindow::MainWindow (String name)  : DocumentWindow(name,Desktop::getInstance().getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId), DocumentWindow::allButtons)
{
    UIWindow* mainWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
}

in this constructor I’d like to make myCoustom ViewController the root controller of this UIWindow?

If you want to do that, my recommendation is to create a static library project from Projucer, and add that as a subproject to your Swift iOS app. Then you will need to set up your C++ <-> Objective-C bridging so that the C++ methods you need are available in your Swift app. Note that Swift Closures translate to Objective-C Blocks which can be cast to std::function - very handy for callbacks from Swift to C++ or vice versa!

2 Likes

If you want to have JUCE handle some of the GUI stuff too, I have some code I can post to help with that too (using the same project structure)

1 Like

You are really kind! if you can I’d like to se that code!

My initial idea was to istantiate the root View controller in juce and after implement all Gui in swift while the core audio/midi using juce. Starting making a Static library from projucer sounds me more Difficult (maybe only for my inexperience).

Thankyou!

Believe me, initially I had a lot of resistance to creating a static library from JUCE and adding it to a project, but it’s a lot less painful than trying to manage your Swift project from Projucer… let JUCE do what its good at and do the rest using the standard tools for creating iOS apps. Then you can use Storyboards etc which you cannot do with a Projucer-created project (AFAIK).

There are a few details to keep in mind, such as header+library search paths - I’ll post something later when I have time…

2 Likes

I really don’t know how to thank you!

Sorry, another little question, there’s no way obviously to add in iOS view some juce gui elements right? (Such as knobs or double range sliders)

Yes there is! I should really write it up as a tutorial. Just super busy at the moment!

2 Likes

:heart_eyes: A tutorial about this topic should be fantastic!!! Don’t worry! I’ll wait for this tutorial (anxiously :joy: haha)!

Really thank you again!

@adamski sorry to bother you, while we wait for the tutorial can you send me maybe some example code as you said? I’m trying to do some experiments on the subject, but the results are not satisfactory :disappointed_relieved:

Thank you in advice!

@ayra.productions sorry, I don’t have the time to write a tutorial at the moment. I sent you a PM

@adamski - I need this so much as well, how can a mere mortal gain access to your knowledge? I am so tired of trying to figure out how to access audio on iOS and MacOS, as it’s so different (even with Mac Catalyst). I want to use JUCE as an audio access layer (with some JUCE components for configuring it) and then use SceneKit (on Metal) for 3D rendering. I’ve been thinking of how this can be achieved, but no results yet. I’ve made this app with JUCE (https://vsound.app), and I would like to replace the rendering with some complicated 3D stuff. Please help, any pointers?