Introduction

1. Derive your C++ class from scapix::bridge::object

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
};

2. Add or change any public function

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
public:
    std::string name();
    void send_message(const std::string& msg, std::shared_ptr<contact> from);
    void add_tags(const std::vector<std::string>& tags);
    void add_friends(std::vector<std::shared_ptr<contact>> friends);
};

3. Press ‘Build’ in whatever IDE you are using

Every time you press ‘Build’ Scapix instantly generates bridge code for all changed classes derived from scapix::bridge::object.

4. Call new functions from UI code

Java

class View {
    private contact = new Contact;

    public void send(Contact friend) {
        contact.sendMessage("Hello", friend);
        contact.addTags({"a","b","c"});
        contact.addFriends({friend});
    }
}

Objective C

@implementation ViewController

-(void) send:(Contact*)friend {
    Contact* c = [Contact new];

    [c sendMessage:@"hello", friend];
    [s addTags:@["a","b","c"]];
    [s addFriends:@[friend]];
}

@end

Swift

class ViewController: UIViewController {
    func send(friend: Contact) {
        let c = Contact()

        contact.sendMessage("Hello", friend)
        contact.addTags(["a","b","c"])
        contact.addFriends([friend])
    }
}

5. Callbacks supported too

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
public:
    void notify(std::function<bool(std::shared_ptr<contact>)>);
};

Java

class View
{
    public void send(Contact friend) {
        friend.notify((Contact c) -> {
            //...
            return true;
        });
    }
}

Objective C

@implementation ViewController

-(void) send:(Contact*)friend {
    [friend notify:^ (Contact* c) {
        //...
        return TRUE;
    }];
}

@end

Swift

class ViewController: UIViewController {
    func send(friend: Contact) {
        friend.notify() {
            (c: Contact) in
            //...
            return true
        }
    }
}

Automatically bridged types

classes derived from scapix::bridge::object
bool
std::int8_t  (char)
std::int16_t (short)
std::int32_t (int)
std::int64_t (long long)
float
double
std::shared_ptr
std::weak_ptr
std::vector
std::map
std::set
std::unordered_map
std::unordered_set
std::function

Objects (of classes derived from scapix::bridge::object) are bridged by reference and should be passed as std::shared_ptr. All other types are bridged by copy.