realm/realm-browser-osx

Exporting List Models To Swift

nallick opened this issue · 2 comments

If the following Node.js code is used to create and populate a realm, then the Realm Browser 3.0.1 (98) is used to save the model definitions to Swift, rather than exporting a list (e.g., let values = List()), it produces an error "Error! 'Any' properties are unsupported in Swift."

const SchemaTestReadOnlySchema = {
    name: 'SchemaTestReadOnly',
    properties: {
      values: 'SchemaTestElement[]'
    }
};

const SchemaTestElementSchema = {
    name: 'SchemaTestElement',
    properties: {
      value: 'int'
    }
};

async function populateSchemaTest(loginUrl: string, realmUrl: string, adminUserName: string, adminUserPassword: string) {
    const adminUser = await Realm.Sync.User.login(loginUrl, adminUserName, adminUserPassword);
    const config = {
        schema: [SchemaTestElementSchema, SchemaTestReadOnlySchema],
        sync: {
            url: realmUrl + "/schema_test_readonly",
            user: adminUser,
        },
    };
    const realm = await Realm.open(config);
    const permissionChange = await adminUser.applyPermissions({userId: "*"}, config.sync.url, "read");
    realm.write(() => {
        const element1 = realm.create("SchemaTestElement", {value: 1});
        const element2 = realm.create("SchemaTestElement", {value: 2});
        const element3 = realm.create("SchemaTestElement", {value: 3});
        const schemaTest = realm.create("SchemaTestReadOnly", {values: [element1, element2, element3]});
    });
}

import Foundation
import RealmSwift

class SchemaTestElement: Object {
  dynamic var value = 0
}

class SchemaTestReadOnly: Object {
  /* Error! 'Any' properties are unsupported in Swift. */
}

That's a bug. It has been fixed in the upcoming release of Realm Studio that will be released soon.
In the meantime, you will have to fix it manually in the model.

should be fixed now